mbed-rtos // fixed error.h
Fork of mbed-rtos by
rtx/RTX_CM_lib.h@18:710466f5cf33, 2014-03-17 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Mar 17 15:00:20 2014 +0000
- Revision:
- 18:710466f5cf33
- Parent:
- 17:771275db0efe
- Child:
- 19:98941d799678
Synchronized with git revision d54a28978c2c22164357e58a338678499e2fadb2
Full URL: https://github.com/mbedmicro/mbed/commit/d54a28978c2c22164357e58a338678499e2fadb2/
[LPC11U35][GCC_ARM][GCC_CR]: Modificatins for build.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 6:350b53afb889 | 1 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 2 | * RL-ARM - RTX |
emilmont | 6:350b53afb889 | 3 | *---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 4 | * Name: RTX_CM_LIB.H |
emilmont | 6:350b53afb889 | 5 | * Purpose: RTX Kernel System Configuration |
emilmont | 6:350b53afb889 | 6 | * Rev.: V4.60 |
emilmont | 6:350b53afb889 | 7 | *---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 8 | * |
emilmont | 6:350b53afb889 | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH |
emilmont | 6:350b53afb889 | 10 | * All rights reserved. |
emilmont | 6:350b53afb889 | 11 | * Redistribution and use in source and binary forms, with or without |
emilmont | 6:350b53afb889 | 12 | * modification, are permitted provided that the following conditions are met: |
emilmont | 6:350b53afb889 | 13 | * - Redistributions of source code must retain the above copyright |
emilmont | 6:350b53afb889 | 14 | * notice, this list of conditions and the following disclaimer. |
emilmont | 6:350b53afb889 | 15 | * - Redistributions in binary form must reproduce the above copyright |
emilmont | 6:350b53afb889 | 16 | * notice, this list of conditions and the following disclaimer in the |
emilmont | 6:350b53afb889 | 17 | * documentation and/or other materials provided with the distribution. |
emilmont | 6:350b53afb889 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
emilmont | 6:350b53afb889 | 19 | * to endorse or promote products derived from this software without |
emilmont | 6:350b53afb889 | 20 | * specific prior written permission. |
emilmont | 6:350b53afb889 | 21 | * |
emilmont | 6:350b53afb889 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
emilmont | 6:350b53afb889 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
emilmont | 6:350b53afb889 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
emilmont | 6:350b53afb889 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
emilmont | 6:350b53afb889 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
emilmont | 6:350b53afb889 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
emilmont | 6:350b53afb889 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
emilmont | 6:350b53afb889 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
emilmont | 6:350b53afb889 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
emilmont | 6:350b53afb889 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
emilmont | 6:350b53afb889 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
emilmont | 6:350b53afb889 | 33 | *---------------------------------------------------------------------------*/ |
emilmont | 9:53e6cccd8782 | 34 | #include "error.h" |
emilmont | 6:350b53afb889 | 35 | |
emilmont | 6:350b53afb889 | 36 | #if defined (__CC_ARM) |
emilmont | 6:350b53afb889 | 37 | #pragma O3 |
emilmont | 6:350b53afb889 | 38 | #define __USED __attribute__((used)) |
emilmont | 6:350b53afb889 | 39 | #elif defined (__GNUC__) |
emilmont | 6:350b53afb889 | 40 | #pragma GCC optimize ("O3") |
emilmont | 6:350b53afb889 | 41 | #define __USED __attribute__((used)) |
emilmont | 6:350b53afb889 | 42 | #elif defined (__ICCARM__) |
emilmont | 6:350b53afb889 | 43 | #define __USED __root |
emilmont | 6:350b53afb889 | 44 | #endif |
emilmont | 6:350b53afb889 | 45 | |
emilmont | 6:350b53afb889 | 46 | |
emilmont | 6:350b53afb889 | 47 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 48 | * Definitions |
emilmont | 6:350b53afb889 | 49 | *---------------------------------------------------------------------------*/ |
emilmont | 6:350b53afb889 | 50 | |
emilmont | 6:350b53afb889 | 51 | #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3] |
emilmont | 6:350b53afb889 | 52 | #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2] |
emilmont | 6:350b53afb889 | 53 | |
emilmont | 6:350b53afb889 | 54 | #define OS_TCB_SIZE 48 |
emilmont | 6:350b53afb889 | 55 | #define OS_TMR_SIZE 8 |
emilmont | 6:350b53afb889 | 56 | |
emilmont | 6:350b53afb889 | 57 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
emilmont | 6:350b53afb889 | 58 | |
emilmont | 6:350b53afb889 | 59 | typedef void *OS_ID; |
emilmont | 6:350b53afb889 | 60 | typedef uint32_t OS_TID; |
emilmont | 6:350b53afb889 | 61 | typedef uint32_t OS_MUT[3]; |
emilmont | 6:350b53afb889 | 62 | typedef uint32_t OS_RESULT; |
emilmont | 6:350b53afb889 | 63 | |
emilmont | 6:350b53afb889 | 64 | #define runtask_id() rt_tsk_self() |
emilmont | 6:350b53afb889 | 65 | #define mutex_init(m) rt_mut_init(m) |
emilmont | 6:350b53afb889 | 66 | #define mutex_wait(m) os_mut_wait(m,0xFFFF) |
emilmont | 6:350b53afb889 | 67 | #define mutex_rel(m) os_mut_release(m) |
emilmont | 6:350b53afb889 | 68 | |
emilmont | 6:350b53afb889 | 69 | extern OS_TID rt_tsk_self (void); |
emilmont | 6:350b53afb889 | 70 | extern void rt_mut_init (OS_ID mutex); |
emilmont | 6:350b53afb889 | 71 | extern OS_RESULT rt_mut_release (OS_ID mutex); |
emilmont | 6:350b53afb889 | 72 | extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout); |
emilmont | 6:350b53afb889 | 73 | |
emilmont | 6:350b53afb889 | 74 | #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout) |
emilmont | 6:350b53afb889 | 75 | #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex) |
emilmont | 6:350b53afb889 | 76 | |
emilmont | 6:350b53afb889 | 77 | OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0); |
emilmont | 6:350b53afb889 | 78 | OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0); |
emilmont | 6:350b53afb889 | 79 | |
emilmont | 6:350b53afb889 | 80 | #endif |
emilmont | 6:350b53afb889 | 81 | |
emilmont | 6:350b53afb889 | 82 | |
emilmont | 6:350b53afb889 | 83 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 84 | * Global Variables |
emilmont | 6:350b53afb889 | 85 | *---------------------------------------------------------------------------*/ |
emilmont | 6:350b53afb889 | 86 | |
emilmont | 6:350b53afb889 | 87 | #if (OS_TIMERS != 0) |
emilmont | 6:350b53afb889 | 88 | #define OS_TASK_CNT (OS_TASKCNT + 1) |
emilmont | 6:350b53afb889 | 89 | #else |
emilmont | 6:350b53afb889 | 90 | #define OS_TASK_CNT OS_TASKCNT |
emilmont | 6:350b53afb889 | 91 | #endif |
emilmont | 6:350b53afb889 | 92 | |
emilmont | 6:350b53afb889 | 93 | uint16_t const os_maxtaskrun = OS_TASK_CNT; |
emilmont | 6:350b53afb889 | 94 | uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT; |
emilmont | 6:350b53afb889 | 95 | uint32_t const os_trv = OS_TRV; |
emilmont | 6:350b53afb889 | 96 | uint8_t const os_flags = OS_RUNPRIV; |
emilmont | 6:350b53afb889 | 97 | |
emilmont | 6:350b53afb889 | 98 | /* Export following defines to uVision debugger. */ |
emilmont | 6:350b53afb889 | 99 | __USED uint32_t const os_clockrate = OS_TICK; |
emilmont | 6:350b53afb889 | 100 | __USED uint32_t const os_timernum = 0; |
emilmont | 6:350b53afb889 | 101 | |
emilmont | 6:350b53afb889 | 102 | /* Stack for the os_idle_demon */ |
emilmont | 6:350b53afb889 | 103 | unsigned int idle_task_stack[OS_IDLESTKSIZE]; |
emilmont | 6:350b53afb889 | 104 | unsigned short const idle_task_stack_size = OS_IDLESTKSIZE; |
emilmont | 6:350b53afb889 | 105 | |
emilmont | 6:350b53afb889 | 106 | #ifndef OS_FIFOSZ |
emilmont | 6:350b53afb889 | 107 | #define OS_FIFOSZ 16 |
emilmont | 6:350b53afb889 | 108 | #endif |
emilmont | 6:350b53afb889 | 109 | |
emilmont | 6:350b53afb889 | 110 | /* Fifo Queue buffer for ISR requests.*/ |
emilmont | 6:350b53afb889 | 111 | uint32_t os_fifo[OS_FIFOSZ*2+1]; |
emilmont | 6:350b53afb889 | 112 | uint8_t const os_fifo_size = OS_FIFOSZ; |
emilmont | 6:350b53afb889 | 113 | |
emilmont | 6:350b53afb889 | 114 | /* An array of Active task pointers. */ |
emilmont | 6:350b53afb889 | 115 | void *os_active_TCB[OS_TASK_CNT]; |
emilmont | 6:350b53afb889 | 116 | |
emilmont | 6:350b53afb889 | 117 | /* User Timers Resources */ |
emilmont | 6:350b53afb889 | 118 | #if (OS_TIMERS != 0) |
emilmont | 6:350b53afb889 | 119 | extern void osTimerThread (void const *argument); |
emilmont | 6:350b53afb889 | 120 | osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ); |
emilmont | 6:350b53afb889 | 121 | osThreadId osThreadId_osTimerThread; |
emilmont | 6:350b53afb889 | 122 | osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *); |
emilmont | 6:350b53afb889 | 123 | osMessageQId osMessageQId_osTimerMessageQ; |
emilmont | 6:350b53afb889 | 124 | #else |
emilmont | 6:350b53afb889 | 125 | osThreadDef_t os_thread_def_osTimerThread = { NULL }; |
emilmont | 6:350b53afb889 | 126 | osThreadId osThreadId_osTimerThread; |
emilmont | 6:350b53afb889 | 127 | osMessageQDef(osTimerMessageQ, 0, void *); |
emilmont | 6:350b53afb889 | 128 | osMessageQId osMessageQId_osTimerMessageQ; |
emilmont | 6:350b53afb889 | 129 | #endif |
emilmont | 6:350b53afb889 | 130 | |
emilmont | 6:350b53afb889 | 131 | |
emilmont | 6:350b53afb889 | 132 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 133 | * RTX Optimizations (empty functions) |
emilmont | 6:350b53afb889 | 134 | *---------------------------------------------------------------------------*/ |
emilmont | 6:350b53afb889 | 135 | |
emilmont | 6:350b53afb889 | 136 | #if OS_ROBIN == 0 |
emilmont | 6:350b53afb889 | 137 | void rt_init_robin (void) {;} |
emilmont | 6:350b53afb889 | 138 | void rt_chk_robin (void) {;} |
emilmont | 6:350b53afb889 | 139 | #endif |
emilmont | 6:350b53afb889 | 140 | |
emilmont | 6:350b53afb889 | 141 | #if OS_STKCHECK == 0 |
emilmont | 6:350b53afb889 | 142 | void rt_stk_check (void) {;} |
emilmont | 6:350b53afb889 | 143 | #endif |
emilmont | 6:350b53afb889 | 144 | |
emilmont | 6:350b53afb889 | 145 | |
emilmont | 6:350b53afb889 | 146 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 147 | * Standard Library multithreading interface |
emilmont | 6:350b53afb889 | 148 | *---------------------------------------------------------------------------*/ |
emilmont | 6:350b53afb889 | 149 | |
emilmont | 6:350b53afb889 | 150 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
emilmont | 6:350b53afb889 | 151 | static OS_MUT std_libmutex[OS_MUTEXCNT]; |
emilmont | 6:350b53afb889 | 152 | static uint32_t nr_mutex; |
emilmont | 6:350b53afb889 | 153 | |
emilmont | 6:350b53afb889 | 154 | /*--------------------------- _mutex_initialize -----------------------------*/ |
emilmont | 6:350b53afb889 | 155 | |
emilmont | 6:350b53afb889 | 156 | int _mutex_initialize (OS_ID *mutex) { |
emilmont | 6:350b53afb889 | 157 | /* Allocate and initialize a system mutex. */ |
emilmont | 6:350b53afb889 | 158 | |
emilmont | 6:350b53afb889 | 159 | if (nr_mutex >= OS_MUTEXCNT) { |
emilmont | 6:350b53afb889 | 160 | /* If you are here, you need to increase the number OS_MUTEXCNT. */ |
emilmont | 9:53e6cccd8782 | 161 | error("Not enough stdlib mutexes\n"); |
emilmont | 6:350b53afb889 | 162 | } |
emilmont | 6:350b53afb889 | 163 | *mutex = &std_libmutex[nr_mutex++]; |
emilmont | 6:350b53afb889 | 164 | mutex_init (*mutex); |
emilmont | 6:350b53afb889 | 165 | return (1); |
emilmont | 6:350b53afb889 | 166 | } |
emilmont | 6:350b53afb889 | 167 | |
emilmont | 6:350b53afb889 | 168 | |
emilmont | 6:350b53afb889 | 169 | /*--------------------------- _mutex_acquire --------------------------------*/ |
emilmont | 6:350b53afb889 | 170 | |
emilmont | 6:350b53afb889 | 171 | __attribute__((used)) void _mutex_acquire (OS_ID *mutex) { |
emilmont | 6:350b53afb889 | 172 | /* Acquire a system mutex, lock stdlib resources. */ |
emilmont | 6:350b53afb889 | 173 | if (runtask_id ()) { |
emilmont | 6:350b53afb889 | 174 | /* RTX running, acquire a mutex. */ |
emilmont | 6:350b53afb889 | 175 | mutex_wait (*mutex); |
emilmont | 6:350b53afb889 | 176 | } |
emilmont | 6:350b53afb889 | 177 | } |
emilmont | 6:350b53afb889 | 178 | |
emilmont | 6:350b53afb889 | 179 | |
emilmont | 6:350b53afb889 | 180 | /*--------------------------- _mutex_release --------------------------------*/ |
emilmont | 6:350b53afb889 | 181 | |
emilmont | 6:350b53afb889 | 182 | __attribute__((used)) void _mutex_release (OS_ID *mutex) { |
emilmont | 6:350b53afb889 | 183 | /* Release a system mutex, unlock stdlib resources. */ |
emilmont | 6:350b53afb889 | 184 | if (runtask_id ()) { |
emilmont | 6:350b53afb889 | 185 | /* RTX running, release a mutex. */ |
emilmont | 6:350b53afb889 | 186 | mutex_rel (*mutex); |
emilmont | 6:350b53afb889 | 187 | } |
emilmont | 6:350b53afb889 | 188 | } |
emilmont | 6:350b53afb889 | 189 | |
emilmont | 6:350b53afb889 | 190 | #endif |
emilmont | 6:350b53afb889 | 191 | |
emilmont | 6:350b53afb889 | 192 | |
emilmont | 6:350b53afb889 | 193 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 194 | * RTX Startup |
emilmont | 6:350b53afb889 | 195 | *---------------------------------------------------------------------------*/ |
emilmont | 6:350b53afb889 | 196 | |
emilmont | 6:350b53afb889 | 197 | /* Main Thread definition */ |
emilmont | 6:350b53afb889 | 198 | extern int main (void); |
emilmont | 6:350b53afb889 | 199 | osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 0, NULL}; |
emilmont | 6:350b53afb889 | 200 | |
emilmont | 6:350b53afb889 | 201 | // This define should be probably moved to the CMSIS layer |
emilmont | 6:350b53afb889 | 202 | #ifdef TARGET_LPC1768 |
emilmont | 6:350b53afb889 | 203 | #define INITIAL_SP (0x10008000UL) |
emilmont | 6:350b53afb889 | 204 | |
mbed_official | 17:771275db0efe | 205 | #elif defined(TARGET_LPC11U24) |
mbed_official | 15:29007aef10a4 | 206 | #define INITIAL_SP (0x10002000UL) |
emilmont | 6:350b53afb889 | 207 | |
mbed_official | 18:710466f5cf33 | 208 | #elif defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) |
mbed_official | 16:f88660a9bed1 | 209 | #define INITIAL_SP (0x10002000UL) |
mbed_official | 16:f88660a9bed1 | 210 | |
mbed_official | 17:771275db0efe | 211 | #elif defined(TARGET_LPC1114) |
bogdanm | 13:869ef732a8a2 | 212 | #define INITIAL_SP (0x10001000UL) |
bogdanm | 13:869ef732a8a2 | 213 | |
mbed_official | 17:771275db0efe | 214 | #elif defined(TARGET_LPC812) |
bogdanm | 14:ee87e782d34f | 215 | #define INITIAL_SP (0x10001000UL) |
bogdanm | 14:ee87e782d34f | 216 | |
mbed_official | 17:771275db0efe | 217 | #elif defined(TARGET_KL25Z) |
emilmont | 10:fcb1f103f7a1 | 218 | #define INITIAL_SP (0x20003000UL) |
emilmont | 10:fcb1f103f7a1 | 219 | |
mbed_official | 17:771275db0efe | 220 | #elif defined(TARGET_LPC4088) |
emilmont | 12:58b30ac3f00e | 221 | #define INITIAL_SP (0x10010000UL) |
emilmont | 12:58b30ac3f00e | 222 | |
mbed_official | 17:771275db0efe | 223 | #elif defined(TARGET_LPC1347) |
bogdanm | 13:869ef732a8a2 | 224 | #define INITIAL_SP (0x10002000UL) |
bogdanm | 13:869ef732a8a2 | 225 | |
emilmont | 6:350b53afb889 | 226 | #endif |
emilmont | 6:350b53afb889 | 227 | |
emilmont | 12:58b30ac3f00e | 228 | #ifdef __CC_ARM |
emilmont | 12:58b30ac3f00e | 229 | extern unsigned char Image$$RW_IRAM1$$ZI$$Limit[]; |
emilmont | 12:58b30ac3f00e | 230 | #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit) |
emilmont | 12:58b30ac3f00e | 231 | #elif defined(__GNUC__) |
mbed_official | 15:29007aef10a4 | 232 | extern unsigned char __end__[]; |
mbed_official | 15:29007aef10a4 | 233 | #define HEAP_START (__end__) |
emilmont | 12:58b30ac3f00e | 234 | #endif |
emilmont | 6:350b53afb889 | 235 | |
emilmont | 6:350b53afb889 | 236 | void set_main_stack(void) { |
emilmont | 12:58b30ac3f00e | 237 | // That is the bottom of the main stack block: no collision detection |
emilmont | 12:58b30ac3f00e | 238 | os_thread_def_main.stack_pointer = HEAP_START; |
emilmont | 12:58b30ac3f00e | 239 | |
emilmont | 6:350b53afb889 | 240 | // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts |
emilmont | 12:58b30ac3f00e | 241 | os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4); |
emilmont | 6:350b53afb889 | 242 | } |
emilmont | 6:350b53afb889 | 243 | |
emilmont | 12:58b30ac3f00e | 244 | #if defined (__CC_ARM) |
emilmont | 6:350b53afb889 | 245 | #ifdef __MICROLIB |
emilmont | 6:350b53afb889 | 246 | void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); |
emilmont | 6:350b53afb889 | 247 | void _main_init (void) { |
emilmont | 6:350b53afb889 | 248 | osKernelInitialize(); |
emilmont | 6:350b53afb889 | 249 | set_main_stack(); |
emilmont | 6:350b53afb889 | 250 | osThreadCreate(&os_thread_def_main, NULL); |
emilmont | 6:350b53afb889 | 251 | osKernelStart(); |
emilmont | 6:350b53afb889 | 252 | for (;;); |
emilmont | 6:350b53afb889 | 253 | } |
emilmont | 6:350b53afb889 | 254 | #else |
emilmont | 6:350b53afb889 | 255 | |
emilmont | 6:350b53afb889 | 256 | /* The single memory model is checking for stack collision at run time, verifing |
emilmont | 6:350b53afb889 | 257 | that the heap pointer is underneath the stack pointer. |
emilmont | 6:350b53afb889 | 258 | |
emilmont | 6:350b53afb889 | 259 | With the RTOS there is not only one stack above the heap, there are multiple |
emilmont | 6:350b53afb889 | 260 | stacks and some of them are underneath the heap pointer. |
emilmont | 6:350b53afb889 | 261 | */ |
emilmont | 6:350b53afb889 | 262 | #pragma import(__use_two_region_memory) |
emilmont | 6:350b53afb889 | 263 | |
emilmont | 6:350b53afb889 | 264 | __asm void __rt_entry (void) { |
emilmont | 6:350b53afb889 | 265 | |
emilmont | 6:350b53afb889 | 266 | IMPORT __user_setup_stackheap |
emilmont | 6:350b53afb889 | 267 | IMPORT __rt_lib_init |
emilmont | 6:350b53afb889 | 268 | IMPORT os_thread_def_main |
emilmont | 6:350b53afb889 | 269 | IMPORT osKernelInitialize |
emilmont | 6:350b53afb889 | 270 | IMPORT set_main_stack |
emilmont | 6:350b53afb889 | 271 | IMPORT osKernelStart |
emilmont | 6:350b53afb889 | 272 | IMPORT osThreadCreate |
emilmont | 6:350b53afb889 | 273 | IMPORT exit |
emilmont | 6:350b53afb889 | 274 | |
emilmont | 6:350b53afb889 | 275 | BL __user_setup_stackheap |
emilmont | 6:350b53afb889 | 276 | MOV R1,R2 |
emilmont | 6:350b53afb889 | 277 | BL __rt_lib_init |
emilmont | 6:350b53afb889 | 278 | BL osKernelInitialize |
emilmont | 6:350b53afb889 | 279 | BL set_main_stack |
emilmont | 6:350b53afb889 | 280 | LDR R0,=os_thread_def_main |
emilmont | 6:350b53afb889 | 281 | MOVS R1,#0 |
emilmont | 6:350b53afb889 | 282 | BL osThreadCreate |
emilmont | 6:350b53afb889 | 283 | BL osKernelStart |
emilmont | 6:350b53afb889 | 284 | BL exit |
emilmont | 6:350b53afb889 | 285 | |
emilmont | 6:350b53afb889 | 286 | ALIGN |
emilmont | 6:350b53afb889 | 287 | } |
emilmont | 6:350b53afb889 | 288 | #endif |
emilmont | 6:350b53afb889 | 289 | |
emilmont | 6:350b53afb889 | 290 | #elif defined (__GNUC__) |
emilmont | 6:350b53afb889 | 291 | |
emilmont | 6:350b53afb889 | 292 | #ifdef __CS3__ |
emilmont | 6:350b53afb889 | 293 | |
emilmont | 6:350b53afb889 | 294 | /* CS3 start_c routine. |
emilmont | 6:350b53afb889 | 295 | * |
emilmont | 6:350b53afb889 | 296 | * Copyright (c) 2006, 2007 CodeSourcery Inc |
emilmont | 6:350b53afb889 | 297 | * |
emilmont | 6:350b53afb889 | 298 | * The authors hereby grant permission to use, copy, modify, distribute, |
emilmont | 6:350b53afb889 | 299 | * and license this software and its documentation for any purpose, provided |
emilmont | 6:350b53afb889 | 300 | * that existing copyright notices are retained in all copies and that this |
emilmont | 6:350b53afb889 | 301 | * notice is included verbatim in any distributions. No written agreement, |
emilmont | 6:350b53afb889 | 302 | * license, or royalty fee is required for any of the authorized uses. |
emilmont | 6:350b53afb889 | 303 | * Modifications to this software may be copyrighted by their authors |
emilmont | 6:350b53afb889 | 304 | * and need not follow the licensing terms described here, provided that |
emilmont | 6:350b53afb889 | 305 | * the new terms are clearly indicated on the first page of each file where |
emilmont | 6:350b53afb889 | 306 | * they apply. |
emilmont | 6:350b53afb889 | 307 | */ |
emilmont | 6:350b53afb889 | 308 | |
emilmont | 6:350b53afb889 | 309 | #include "cs3.h" |
emilmont | 6:350b53afb889 | 310 | |
emilmont | 6:350b53afb889 | 311 | extern void __libc_init_array (void); |
emilmont | 6:350b53afb889 | 312 | |
emilmont | 6:350b53afb889 | 313 | __attribute ((noreturn)) void __cs3_start_c (void){ |
emilmont | 6:350b53afb889 | 314 | unsigned regions = __cs3_region_num; |
emilmont | 6:350b53afb889 | 315 | const struct __cs3_region *rptr = __cs3_regions; |
emilmont | 6:350b53afb889 | 316 | |
emilmont | 6:350b53afb889 | 317 | /* Initialize memory */ |
emilmont | 6:350b53afb889 | 318 | for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) { |
emilmont | 6:350b53afb889 | 319 | long long *src = (long long *)rptr->init; |
emilmont | 6:350b53afb889 | 320 | long long *dst = (long long *)rptr->data; |
emilmont | 6:350b53afb889 | 321 | unsigned limit = rptr->init_size; |
emilmont | 6:350b53afb889 | 322 | unsigned count; |
emilmont | 6:350b53afb889 | 323 | |
emilmont | 6:350b53afb889 | 324 | if (src != dst) |
emilmont | 6:350b53afb889 | 325 | for (count = 0; count != limit; count += sizeof (long long)) |
emilmont | 6:350b53afb889 | 326 | *dst++ = *src++; |
emilmont | 6:350b53afb889 | 327 | else |
emilmont | 6:350b53afb889 | 328 | dst = (long long *)((char *)dst + limit); |
emilmont | 6:350b53afb889 | 329 | limit = rptr->zero_size; |
emilmont | 6:350b53afb889 | 330 | for (count = 0; count != limit; count += sizeof (long long)) |
emilmont | 6:350b53afb889 | 331 | *dst++ = 0; |
emilmont | 6:350b53afb889 | 332 | } |
emilmont | 6:350b53afb889 | 333 | |
emilmont | 6:350b53afb889 | 334 | /* Run initializers. */ |
emilmont | 6:350b53afb889 | 335 | __libc_init_array (); |
emilmont | 6:350b53afb889 | 336 | |
emilmont | 6:350b53afb889 | 337 | osKernelInitialize(); |
emilmont | 12:58b30ac3f00e | 338 | set_main_stack(); |
emilmont | 6:350b53afb889 | 339 | osThreadCreate(&os_thread_def_main, NULL); |
emilmont | 6:350b53afb889 | 340 | osKernelStart(); |
emilmont | 6:350b53afb889 | 341 | for (;;); |
emilmont | 6:350b53afb889 | 342 | } |
emilmont | 6:350b53afb889 | 343 | |
emilmont | 6:350b53afb889 | 344 | #else |
emilmont | 6:350b53afb889 | 345 | |
emilmont | 6:350b53afb889 | 346 | __attribute__((naked)) void software_init_hook (void) { |
emilmont | 6:350b53afb889 | 347 | __asm ( |
emilmont | 6:350b53afb889 | 348 | ".syntax unified\n" |
emilmont | 6:350b53afb889 | 349 | ".thumb\n" |
emilmont | 6:350b53afb889 | 350 | "movs r0,#0\n" |
emilmont | 6:350b53afb889 | 351 | "movs r1,#0\n" |
emilmont | 6:350b53afb889 | 352 | "mov r4,r0\n" |
emilmont | 6:350b53afb889 | 353 | "mov r5,r1\n" |
emilmont | 6:350b53afb889 | 354 | "ldr r0,= __libc_fini_array\n" |
emilmont | 6:350b53afb889 | 355 | "bl atexit\n" |
emilmont | 6:350b53afb889 | 356 | "bl __libc_init_array\n" |
emilmont | 6:350b53afb889 | 357 | "mov r0,r4\n" |
emilmont | 6:350b53afb889 | 358 | "mov r1,r5\n" |
emilmont | 6:350b53afb889 | 359 | "bl osKernelInitialize\n" |
emilmont | 12:58b30ac3f00e | 360 | "bl set_main_stack\n" |
emilmont | 6:350b53afb889 | 361 | "ldr r0,=os_thread_def_main\n" |
emilmont | 6:350b53afb889 | 362 | "movs r1,#0\n" |
emilmont | 6:350b53afb889 | 363 | "bl osThreadCreate\n" |
emilmont | 6:350b53afb889 | 364 | "bl osKernelStart\n" |
emilmont | 6:350b53afb889 | 365 | "bl exit\n" |
emilmont | 6:350b53afb889 | 366 | ); |
emilmont | 6:350b53afb889 | 367 | } |
emilmont | 6:350b53afb889 | 368 | |
emilmont | 6:350b53afb889 | 369 | #endif |
emilmont | 6:350b53afb889 | 370 | |
emilmont | 6:350b53afb889 | 371 | #elif defined (__ICCARM__) |
emilmont | 6:350b53afb889 | 372 | |
emilmont | 6:350b53afb889 | 373 | extern int __low_level_init(void); |
emilmont | 6:350b53afb889 | 374 | extern void __iar_data_init3(void); |
emilmont | 6:350b53afb889 | 375 | extern void exit(int arg); |
emilmont | 6:350b53afb889 | 376 | |
emilmont | 6:350b53afb889 | 377 | __noreturn __stackless void __cmain(void) { |
emilmont | 6:350b53afb889 | 378 | int a; |
emilmont | 6:350b53afb889 | 379 | |
emilmont | 6:350b53afb889 | 380 | if (__low_level_init() != 0) { |
emilmont | 6:350b53afb889 | 381 | __iar_data_init3(); |
emilmont | 6:350b53afb889 | 382 | } |
emilmont | 6:350b53afb889 | 383 | osKernelInitialize(); |
emilmont | 6:350b53afb889 | 384 | osThreadCreate(&os_thread_def_main, NULL); |
emilmont | 6:350b53afb889 | 385 | a = osKernelStart(); |
emilmont | 6:350b53afb889 | 386 | exit(a); |
emilmont | 6:350b53afb889 | 387 | } |
emilmont | 6:350b53afb889 | 388 | |
emilmont | 6:350b53afb889 | 389 | #endif |
emilmont | 6:350b53afb889 | 390 | |
emilmont | 6:350b53afb889 | 391 | |
emilmont | 6:350b53afb889 | 392 | /*---------------------------------------------------------------------------- |
emilmont | 6:350b53afb889 | 393 | * end of file |
emilmont | 6:350b53afb889 | 394 | *---------------------------------------------------------------------------*/ |
emilmont | 6:350b53afb889 | 395 |