Versie 0.2 Het versturen via de NRF werkt nog niet helemaal omdat er per 4 bytes verstuurd moet worden. Wordt gefixt d.m.v. dynamic stuff!

Dependencies:   BufferedSerial

Dependents:   rtos_basic rtos_basic

Fork of mbed-rtos by mbed official

Committer:
mbed_official
Date:
Thu Nov 06 13:00:11 2014 +0000
Revision:
49:77c8e4604045
Child:
50:64a5202c3676
Synchronized with git revision 7b90c2ba137baaf9769219e0e8a7b8e8d1299c4f

Full URL: https://github.com/mbedmicro/mbed/commit/7b90c2ba137baaf9769219e0e8a7b8e8d1299c4f/

This target is not yet tested, so it can't be released as part of the official
SDK build for now.

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 49:77c8e4604045 226 #elif defined(TARGET_KL46Z)
mbed_official 49:77c8e4604045 227 #define INITIAL_SP (0x20006000UL)
mbed_official 49:77c8e4604045 228
mbed_official 49:77c8e4604045 229 #elif defined(TARGET_KL43Z)
mbed_official 49:77c8e4604045 230 #define INITIAL_SP (0x20006000UL)
mbed_official 49:77c8e4604045 231
mbed_official 49:77c8e4604045 232 #elif defined(TARGET_KL05Z)
mbed_official 49:77c8e4604045 233 #define INITIAL_SP (0x20000C00UL)
mbed_official 49:77c8e4604045 234
mbed_official 49:77c8e4604045 235 #elif defined(TARGET_LPC4088)
mbed_official 49:77c8e4604045 236 #define INITIAL_SP (0x10010000UL)
mbed_official 49:77c8e4604045 237
mbed_official 49:77c8e4604045 238 #elif defined(TARGET_LPC4337)
mbed_official 49:77c8e4604045 239 #define INITIAL_SP (0x10008000UL)
mbed_official 49:77c8e4604045 240
mbed_official 49:77c8e4604045 241 #elif defined(TARGET_LPC1347)
mbed_official 49:77c8e4604045 242 #define INITIAL_SP (0x10002000UL)
mbed_official 49:77c8e4604045 243
mbed_official 49:77c8e4604045 244 #elif defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8)
mbed_official 49:77c8e4604045 245 #define INITIAL_SP (0x20002000UL)
mbed_official 49:77c8e4604045 246
mbed_official 49:77c8e4604045 247 #elif defined(TARGET_DISCO_F303VC)
mbed_official 49:77c8e4604045 248 #define INITIAL_SP (0x2000A000UL)
mbed_official 49:77c8e4604045 249
mbed_official 49:77c8e4604045 250 #elif defined(TARGET_STM32F407) || defined(TARGET_F407VG)
mbed_official 49:77c8e4604045 251 #define INITIAL_SP (0x20020000UL)
mbed_official 49:77c8e4604045 252
mbed_official 49:77c8e4604045 253 #elif defined(TARGET_STM32F401RE)
mbed_official 49:77c8e4604045 254 #define INITIAL_SP (0x20018000UL)
mbed_official 49:77c8e4604045 255
mbed_official 49:77c8e4604045 256 #elif defined(TARGET_LPC1549)
mbed_official 49:77c8e4604045 257 #define INITIAL_SP (0x02009000UL)
mbed_official 49:77c8e4604045 258
mbed_official 49:77c8e4604045 259 #elif defined(TARGET_LPC11U68)
mbed_official 49:77c8e4604045 260 #define INITIAL_SP (0x10004000UL)
mbed_official 49:77c8e4604045 261
mbed_official 49:77c8e4604045 262 #elif defined(TARGET_NRF51822)
mbed_official 49:77c8e4604045 263 #define INITIAL_SP (0x20004000UL)
mbed_official 49:77c8e4604045 264
mbed_official 49:77c8e4604045 265 #elif defined(TARGET_STM32F411RE)
mbed_official 49:77c8e4604045 266 #define INITIAL_SP (0x20020000UL)
mbed_official 49:77c8e4604045 267
mbed_official 49:77c8e4604045 268 #elif defined(TARGET_STM32F103RB)
mbed_official 49:77c8e4604045 269 #define INITIAL_SP (0x20005000UL)
mbed_official 49:77c8e4604045 270
mbed_official 49:77c8e4604045 271 #elif defined(TARGET_STM32F302R8)
mbed_official 49:77c8e4604045 272 #define INITIAL_SP (0x20004000UL)
mbed_official 49:77c8e4604045 273
mbed_official 49:77c8e4604045 274 #elif defined(TARGET_STM32F334R8)
mbed_official 49:77c8e4604045 275 #define INITIAL_SP (0x20003000UL)
mbed_official 49:77c8e4604045 276
mbed_official 49:77c8e4604045 277 #elif defined(TARGET_STM32F334C8)
mbed_official 49:77c8e4604045 278 #define INITIAL_SP (0x20003000UL)
mbed_official 49:77c8e4604045 279
mbed_official 49:77c8e4604045 280 #else
mbed_official 49:77c8e4604045 281 #error "no target defined"
mbed_official 49:77c8e4604045 282
mbed_official 49:77c8e4604045 283 #endif
mbed_official 49:77c8e4604045 284
mbed_official 49:77c8e4604045 285 #ifdef __CC_ARM
mbed_official 49:77c8e4604045 286 extern unsigned char Image$$RW_IRAM1$$ZI$$Limit[];
mbed_official 49:77c8e4604045 287 #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit)
mbed_official 49:77c8e4604045 288 #elif defined(__GNUC__)
mbed_official 49:77c8e4604045 289 extern unsigned char __end__[];
mbed_official 49:77c8e4604045 290 #define HEAP_START (__end__)
mbed_official 49:77c8e4604045 291 #endif
mbed_official 49:77c8e4604045 292
mbed_official 49:77c8e4604045 293 void set_main_stack(void) {
mbed_official 49:77c8e4604045 294 // That is the bottom of the main stack block: no collision detection
mbed_official 49:77c8e4604045 295 os_thread_def_main.stack_pointer = HEAP_START;
mbed_official 49:77c8e4604045 296
mbed_official 49:77c8e4604045 297 // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts
mbed_official 49:77c8e4604045 298 os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4);
mbed_official 49:77c8e4604045 299 }
mbed_official 49:77c8e4604045 300
mbed_official 49:77c8e4604045 301 #if defined (__CC_ARM)
mbed_official 49:77c8e4604045 302 #ifdef __MICROLIB
mbed_official 49:77c8e4604045 303 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
mbed_official 49:77c8e4604045 304 void _main_init (void) {
mbed_official 49:77c8e4604045 305 osKernelInitialize();
mbed_official 49:77c8e4604045 306 set_main_stack();
mbed_official 49:77c8e4604045 307 osThreadCreate(&os_thread_def_main, NULL);
mbed_official 49:77c8e4604045 308 osKernelStart();
mbed_official 49:77c8e4604045 309 for (;;);
mbed_official 49:77c8e4604045 310 }
mbed_official 49:77c8e4604045 311 #else
mbed_official 49:77c8e4604045 312
mbed_official 49:77c8e4604045 313 /* The single memory model is checking for stack collision at run time, verifing
mbed_official 49:77c8e4604045 314 that the heap pointer is underneath the stack pointer.
mbed_official 49:77c8e4604045 315
mbed_official 49:77c8e4604045 316 With the RTOS there is not only one stack above the heap, there are multiple
mbed_official 49:77c8e4604045 317 stacks and some of them are underneath the heap pointer.
mbed_official 49:77c8e4604045 318 */
mbed_official 49:77c8e4604045 319 #pragma import(__use_two_region_memory)
mbed_official 49:77c8e4604045 320
mbed_official 49:77c8e4604045 321 __asm void __rt_entry (void) {
mbed_official 49:77c8e4604045 322
mbed_official 49:77c8e4604045 323 IMPORT __user_setup_stackheap
mbed_official 49:77c8e4604045 324 IMPORT __rt_lib_init
mbed_official 49:77c8e4604045 325 IMPORT os_thread_def_main
mbed_official 49:77c8e4604045 326 IMPORT osKernelInitialize
mbed_official 49:77c8e4604045 327 IMPORT set_main_stack
mbed_official 49:77c8e4604045 328 IMPORT osKernelStart
mbed_official 49:77c8e4604045 329 IMPORT osThreadCreate
mbed_official 49:77c8e4604045 330 IMPORT exit
mbed_official 49:77c8e4604045 331
mbed_official 49:77c8e4604045 332 BL __user_setup_stackheap
mbed_official 49:77c8e4604045 333 MOV R1,R2
mbed_official 49:77c8e4604045 334 BL __rt_lib_init
mbed_official 49:77c8e4604045 335 BL osKernelInitialize
mbed_official 49:77c8e4604045 336 BL set_main_stack
mbed_official 49:77c8e4604045 337 LDR R0,=os_thread_def_main
mbed_official 49:77c8e4604045 338 MOVS R1,#0
mbed_official 49:77c8e4604045 339 BL osThreadCreate
mbed_official 49:77c8e4604045 340 BL osKernelStart
mbed_official 49:77c8e4604045 341 BL exit
mbed_official 49:77c8e4604045 342
mbed_official 49:77c8e4604045 343 ALIGN
mbed_official 49:77c8e4604045 344 }
mbed_official 49:77c8e4604045 345 #endif
mbed_official 49:77c8e4604045 346
mbed_official 49:77c8e4604045 347 #elif defined (__GNUC__)
mbed_official 49:77c8e4604045 348
mbed_official 49:77c8e4604045 349 #ifdef __CS3__
mbed_official 49:77c8e4604045 350
mbed_official 49:77c8e4604045 351 /* CS3 start_c routine.
mbed_official 49:77c8e4604045 352 *
mbed_official 49:77c8e4604045 353 * Copyright (c) 2006, 2007 CodeSourcery Inc
mbed_official 49:77c8e4604045 354 *
mbed_official 49:77c8e4604045 355 * The authors hereby grant permission to use, copy, modify, distribute,
mbed_official 49:77c8e4604045 356 * and license this software and its documentation for any purpose, provided
mbed_official 49:77c8e4604045 357 * that existing copyright notices are retained in all copies and that this
mbed_official 49:77c8e4604045 358 * notice is included verbatim in any distributions. No written agreement,
mbed_official 49:77c8e4604045 359 * license, or royalty fee is required for any of the authorized uses.
mbed_official 49:77c8e4604045 360 * Modifications to this software may be copyrighted by their authors
mbed_official 49:77c8e4604045 361 * and need not follow the licensing terms described here, provided that
mbed_official 49:77c8e4604045 362 * the new terms are clearly indicated on the first page of each file where
mbed_official 49:77c8e4604045 363 * they apply.
mbed_official 49:77c8e4604045 364 */
mbed_official 49:77c8e4604045 365
mbed_official 49:77c8e4604045 366 #include "cs3.h"
mbed_official 49:77c8e4604045 367
mbed_official 49:77c8e4604045 368 extern void __libc_init_array (void);
mbed_official 49:77c8e4604045 369
mbed_official 49:77c8e4604045 370 __attribute ((noreturn)) void __cs3_start_c (void){
mbed_official 49:77c8e4604045 371 unsigned regions = __cs3_region_num;
mbed_official 49:77c8e4604045 372 const struct __cs3_region *rptr = __cs3_regions;
mbed_official 49:77c8e4604045 373
mbed_official 49:77c8e4604045 374 /* Initialize memory */
mbed_official 49:77c8e4604045 375 for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) {
mbed_official 49:77c8e4604045 376 long long *src = (long long *)rptr->init;
mbed_official 49:77c8e4604045 377 long long *dst = (long long *)rptr->data;
mbed_official 49:77c8e4604045 378 unsigned limit = rptr->init_size;
mbed_official 49:77c8e4604045 379 unsigned count;
mbed_official 49:77c8e4604045 380
mbed_official 49:77c8e4604045 381 if (src != dst)
mbed_official 49:77c8e4604045 382 for (count = 0; count != limit; count += sizeof (long long))
mbed_official 49:77c8e4604045 383 *dst++ = *src++;
mbed_official 49:77c8e4604045 384 else
mbed_official 49:77c8e4604045 385 dst = (long long *)((char *)dst + limit);
mbed_official 49:77c8e4604045 386 limit = rptr->zero_size;
mbed_official 49:77c8e4604045 387 for (count = 0; count != limit; count += sizeof (long long))
mbed_official 49:77c8e4604045 388 *dst++ = 0;
mbed_official 49:77c8e4604045 389 }
mbed_official 49:77c8e4604045 390
mbed_official 49:77c8e4604045 391 /* Run initializers. */
mbed_official 49:77c8e4604045 392 __libc_init_array ();
mbed_official 49:77c8e4604045 393
mbed_official 49:77c8e4604045 394 osKernelInitialize();
mbed_official 49:77c8e4604045 395 set_main_stack();
mbed_official 49:77c8e4604045 396 osThreadCreate(&os_thread_def_main, NULL);
mbed_official 49:77c8e4604045 397 osKernelStart();
mbed_official 49:77c8e4604045 398 for (;;);
mbed_official 49:77c8e4604045 399 }
mbed_official 49:77c8e4604045 400
mbed_official 49:77c8e4604045 401 #else
mbed_official 49:77c8e4604045 402
mbed_official 49:77c8e4604045 403 __attribute__((naked)) void software_init_hook (void) {
mbed_official 49:77c8e4604045 404 __asm (
mbed_official 49:77c8e4604045 405 ".syntax unified\n"
mbed_official 49:77c8e4604045 406 ".thumb\n"
mbed_official 49:77c8e4604045 407 "movs r0,#0\n"
mbed_official 49:77c8e4604045 408 "movs r1,#0\n"
mbed_official 49:77c8e4604045 409 "mov r4,r0\n"
mbed_official 49:77c8e4604045 410 "mov r5,r1\n"
mbed_official 49:77c8e4604045 411 "ldr r0,= __libc_fini_array\n"
mbed_official 49:77c8e4604045 412 "bl atexit\n"
mbed_official 49:77c8e4604045 413 "bl __libc_init_array\n"
mbed_official 49:77c8e4604045 414 "mov r0,r4\n"
mbed_official 49:77c8e4604045 415 "mov r1,r5\n"
mbed_official 49:77c8e4604045 416 "bl osKernelInitialize\n"
mbed_official 49:77c8e4604045 417 "bl set_main_stack\n"
mbed_official 49:77c8e4604045 418 "ldr r0,=os_thread_def_main\n"
mbed_official 49:77c8e4604045 419 "movs r1,#0\n"
mbed_official 49:77c8e4604045 420 "bl osThreadCreate\n"
mbed_official 49:77c8e4604045 421 "bl osKernelStart\n"
mbed_official 49:77c8e4604045 422 "bl exit\n"
mbed_official 49:77c8e4604045 423 );
mbed_official 49:77c8e4604045 424 }
mbed_official 49:77c8e4604045 425
mbed_official 49:77c8e4604045 426 #endif
mbed_official 49:77c8e4604045 427
mbed_official 49:77c8e4604045 428 #elif defined (__ICCARM__)
mbed_official 49:77c8e4604045 429
mbed_official 49:77c8e4604045 430 extern int __low_level_init(void);
mbed_official 49:77c8e4604045 431 extern void __iar_data_init3(void);
mbed_official 49:77c8e4604045 432 extern void exit(int arg);
mbed_official 49:77c8e4604045 433
mbed_official 49:77c8e4604045 434 __noreturn __stackless void __cmain(void) {
mbed_official 49:77c8e4604045 435 int a;
mbed_official 49:77c8e4604045 436
mbed_official 49:77c8e4604045 437 if (__low_level_init() != 0) {
mbed_official 49:77c8e4604045 438 __iar_data_init3();
mbed_official 49:77c8e4604045 439 }
mbed_official 49:77c8e4604045 440 osKernelInitialize();
mbed_official 49:77c8e4604045 441 osThreadCreate(&os_thread_def_main, NULL);
mbed_official 49:77c8e4604045 442 a = osKernelStart();
mbed_official 49:77c8e4604045 443 exit(a);
mbed_official 49:77c8e4604045 444 }
mbed_official 49:77c8e4604045 445
mbed_official 49:77c8e4604045 446 #endif
mbed_official 49:77c8e4604045 447
mbed_official 49:77c8e4604045 448
mbed_official 49:77c8e4604045 449 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 450 * end of file
mbed_official 49:77c8e4604045 451 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 452
mbed_official 49:77c8e4604045 453