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 13 08:30:27 2014 +0000
Revision:
50:64a5202c3676
Parent:
49:77c8e4604045
Child:
52:02f5cf381388
Synchronized with git revision 08c85ef1361a8a0c66ab4c27be8f4fd9f032a14c

Full URL: https://github.com/mbedmicro/mbed/commit/08c85ef1361a8a0c66ab4c27be8f4fd9f032a14c/

Platform: Add support for MultiTech mDot module

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