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