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