Rtos code cntains bug possible incompatability with I2C
Fork of mbed-rtos by
rtx/TARGET_CORTEX_A/RTX_CM_lib.h@118:4c105b8d7cae, 2016-05-23 (annotated)
- Committer:
- mbed_official
- Date:
- Mon May 23 11:00:15 2016 +0100
- Revision:
- 118:4c105b8d7cae
- Parent:
- 117:0788b1a76461
Synchronized with git revision 821c492eb84a24748de5c05c17f7bd9380ca28ff
Full URL: https://github.com/mbedmicro/mbed/commit/821c492eb84a24748de5c05c17f7bd9380ca28ff/
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 | 92:bc9729798a19 | 6 | * Rev.: V4.73 |
mbed_official | 48:e9a2c7cb57a4 | 7 | *---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 8 | * |
mbed_official | 92:bc9729798a19 | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2013 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 | 68:d3d0e710b443 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
mbed_official | 68:d3d0e710b443 | 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 | 68:d3d0e710b443 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 68:d3d0e710b443 | 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 | 68:d3d0e710b443 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
mbed_official | 68:d3d0e710b443 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
mbed_official | 68:d3d0e710b443 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
mbed_official | 68:d3d0e710b443 | 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 | 92:bc9729798a19 | 53 | #define OS_TCB_SIZE 52 |
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 | 92:bc9729798a19 | 60 | typedef uint32_t OS_MUT[4]; |
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 | 103:5a85840ab54e | 79 | #elif defined (__ICCARM__) |
mbed_official | 103:5a85840ab54e | 80 | |
mbed_official | 103:5a85840ab54e | 81 | typedef void *OS_ID; |
mbed_official | 103:5a85840ab54e | 82 | typedef uint32_t OS_TID; |
mbed_official | 103:5a85840ab54e | 83 | typedef uint32_t OS_MUT[4]; |
mbed_official | 103:5a85840ab54e | 84 | typedef uint32_t OS_RESULT; |
mbed_official | 103:5a85840ab54e | 85 | |
mbed_official | 103:5a85840ab54e | 86 | #define runtask_id() rt_tsk_self() |
mbed_official | 103:5a85840ab54e | 87 | #define mutex_init(m) rt_mut_init(m) |
mbed_official | 103:5a85840ab54e | 88 | #define mutex_del(m) os_mut_delete(m) |
mbed_official | 103:5a85840ab54e | 89 | #define mutex_wait(m) os_mut_wait(m,0xFFFF) |
mbed_official | 103:5a85840ab54e | 90 | #define mutex_rel(m) os_mut_release(m) |
mbed_official | 103:5a85840ab54e | 91 | |
mbed_official | 103:5a85840ab54e | 92 | extern OS_TID rt_tsk_self (void); |
mbed_official | 103:5a85840ab54e | 93 | extern void rt_mut_init (OS_ID mutex); |
mbed_official | 103:5a85840ab54e | 94 | extern OS_RESULT rt_mut_delete (OS_ID mutex); |
mbed_official | 103:5a85840ab54e | 95 | extern OS_RESULT rt_mut_release (OS_ID mutex); |
mbed_official | 103:5a85840ab54e | 96 | extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout); |
mbed_official | 103:5a85840ab54e | 97 | |
mbed_official | 103:5a85840ab54e | 98 | #pragma swi_number=0 |
mbed_official | 103:5a85840ab54e | 99 | __swi OS_RESULT _os_mut_delete (OS_ID mutex); |
mbed_official | 103:5a85840ab54e | 100 | |
mbed_official | 103:5a85840ab54e | 101 | static inline OS_RESULT os_mut_delete(OS_ID mutex) |
mbed_official | 103:5a85840ab54e | 102 | { |
mbed_official | 103:5a85840ab54e | 103 | __asm("mov r12,%0\n" :: "r"(&rt_mut_delete) : "r12" ); |
mbed_official | 103:5a85840ab54e | 104 | return _os_mut_delete(mutex); |
mbed_official | 103:5a85840ab54e | 105 | } |
mbed_official | 103:5a85840ab54e | 106 | |
mbed_official | 103:5a85840ab54e | 107 | #pragma swi_number=0 |
mbed_official | 103:5a85840ab54e | 108 | __swi OS_RESULT _os_mut_release (OS_ID mutex); |
mbed_official | 103:5a85840ab54e | 109 | |
mbed_official | 103:5a85840ab54e | 110 | static inline OS_RESULT os_mut_release(OS_ID mutex) |
mbed_official | 103:5a85840ab54e | 111 | { |
mbed_official | 103:5a85840ab54e | 112 | __asm("mov r12,%0\n" :: "r"(&rt_mut_release) : "r12" ); |
mbed_official | 103:5a85840ab54e | 113 | return _os_mut_release(mutex); |
mbed_official | 103:5a85840ab54e | 114 | } |
mbed_official | 103:5a85840ab54e | 115 | |
mbed_official | 103:5a85840ab54e | 116 | #pragma swi_number=0 |
mbed_official | 103:5a85840ab54e | 117 | __swi OS_RESULT _os_mut_wait (OS_ID mutex, uint16_t timeout); |
mbed_official | 103:5a85840ab54e | 118 | |
mbed_official | 103:5a85840ab54e | 119 | static inline OS_RESULT os_mut_wait(OS_ID mutex, uint16_t timeout) |
mbed_official | 103:5a85840ab54e | 120 | { |
mbed_official | 103:5a85840ab54e | 121 | __asm("mov r12,%0\n" :: "r"(&rt_mut_wait) : "r12" ); |
mbed_official | 103:5a85840ab54e | 122 | return _os_mut_wait(mutex, timeout); |
mbed_official | 103:5a85840ab54e | 123 | } |
mbed_official | 103:5a85840ab54e | 124 | |
mbed_official | 103:5a85840ab54e | 125 | #include <yvals.h> /* for include DLib_Thread.h */ |
mbed_official | 103:5a85840ab54e | 126 | |
mbed_official | 103:5a85840ab54e | 127 | void __iar_system_Mtxinit(__iar_Rmtx *); |
mbed_official | 103:5a85840ab54e | 128 | void __iar_system_Mtxdst(__iar_Rmtx *); |
mbed_official | 103:5a85840ab54e | 129 | void __iar_system_Mtxlock(__iar_Rmtx *); |
mbed_official | 103:5a85840ab54e | 130 | void __iar_system_Mtxunlock(__iar_Rmtx *); |
mbed_official | 103:5a85840ab54e | 131 | |
mbed_official | 103:5a85840ab54e | 132 | |
mbed_official | 103:5a85840ab54e | 133 | |
mbed_official | 103:5a85840ab54e | 134 | |
mbed_official | 48:e9a2c7cb57a4 | 135 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 136 | |
mbed_official | 48:e9a2c7cb57a4 | 137 | |
mbed_official | 48:e9a2c7cb57a4 | 138 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 139 | * Global Variables |
mbed_official | 48:e9a2c7cb57a4 | 140 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 141 | |
mbed_official | 48:e9a2c7cb57a4 | 142 | #if (OS_TIMERS != 0) |
mbed_official | 48:e9a2c7cb57a4 | 143 | #define OS_TASK_CNT (OS_TASKCNT + 1) |
mbed_official | 85:ef0a22cdf839 | 144 | #ifndef __MBED_CMSIS_RTOS_CA9 |
mbed_official | 48:e9a2c7cb57a4 | 145 | #define OS_PRIV_CNT (OS_PRIVCNT + 2) |
mbed_official | 48:e9a2c7cb57a4 | 146 | #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ)) |
mbed_official | 85:ef0a22cdf839 | 147 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 148 | #else |
mbed_official | 48:e9a2c7cb57a4 | 149 | #define OS_TASK_CNT OS_TASKCNT |
mbed_official | 85:ef0a22cdf839 | 150 | #ifndef __MBED_CMSIS_RTOS_CA9 |
mbed_official | 48:e9a2c7cb57a4 | 151 | #define OS_PRIV_CNT (OS_PRIVCNT + 1) |
mbed_official | 48:e9a2c7cb57a4 | 152 | #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE)) |
mbed_official | 48:e9a2c7cb57a4 | 153 | #endif |
mbed_official | 85:ef0a22cdf839 | 154 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 155 | |
mbed_official | 48:e9a2c7cb57a4 | 156 | uint16_t const os_maxtaskrun = OS_TASK_CNT; |
mbed_official | 85:ef0a22cdf839 | 157 | #ifdef __MBED_CMSIS_RTOS_CA9 |
mbed_official | 85:ef0a22cdf839 | 158 | uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_IDLESTKSIZE*4); |
mbed_official | 85:ef0a22cdf839 | 159 | #else |
mbed_official | 48:e9a2c7cb57a4 | 160 | uint32_t const os_stackinfo = (OS_STKCHECK<<24)| (OS_PRIV_CNT<<16) | (OS_STKSIZE*4); |
mbed_official | 85:ef0a22cdf839 | 161 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 162 | uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT; |
mbed_official | 92:bc9729798a19 | 163 | uint32_t const os_tickfreq = OS_CLOCK; |
mbed_official | 92:bc9729798a19 | 164 | uint16_t const os_tickus_i = OS_CLOCK/1000000; |
mbed_official | 92:bc9729798a19 | 165 | uint16_t const os_tickus_f = (((uint64_t)(OS_CLOCK-1000000*(OS_CLOCK/1000000)))<<16)/1000000; |
mbed_official | 48:e9a2c7cb57a4 | 166 | uint32_t const os_trv = OS_TRV; |
mbed_official | 48:e9a2c7cb57a4 | 167 | uint8_t const os_flags = OS_RUNPRIV; |
mbed_official | 48:e9a2c7cb57a4 | 168 | |
mbed_official | 48:e9a2c7cb57a4 | 169 | /* Export following defines to uVision debugger. */ |
mbed_official | 92:bc9729798a19 | 170 | __USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS; |
mbed_official | 92:bc9729798a19 | 171 | __USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX; |
mbed_official | 48:e9a2c7cb57a4 | 172 | __USED uint32_t const os_clockrate = OS_TICK; |
mbed_official | 48:e9a2c7cb57a4 | 173 | __USED uint32_t const os_timernum = 0; |
mbed_official | 48:e9a2c7cb57a4 | 174 | |
mbed_official | 48:e9a2c7cb57a4 | 175 | /* Memory pool for TCB allocation */ |
mbed_official | 48:e9a2c7cb57a4 | 176 | _declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT); |
mbed_official | 48:e9a2c7cb57a4 | 177 | uint16_t const mp_tcb_size = sizeof(mp_tcb); |
mbed_official | 48:e9a2c7cb57a4 | 178 | |
mbed_official | 85:ef0a22cdf839 | 179 | #ifdef __MBED_CMSIS_RTOS_CA9 |
mbed_official | 85:ef0a22cdf839 | 180 | /* Memory pool for os_idle_demon stack allocation. */ |
mbed_official | 85:ef0a22cdf839 | 181 | _declare_box8 (mp_stk, OS_IDLESTKSIZE*4, 1); |
mbed_official | 85:ef0a22cdf839 | 182 | uint32_t const mp_stk_size = sizeof(mp_stk); |
mbed_official | 85:ef0a22cdf839 | 183 | #else |
mbed_official | 48:e9a2c7cb57a4 | 184 | /* Memory pool for System stack allocation (+os_idle_demon). */ |
mbed_official | 48:e9a2c7cb57a4 | 185 | _declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1); |
mbed_official | 48:e9a2c7cb57a4 | 186 | uint32_t const mp_stk_size = sizeof(mp_stk); |
mbed_official | 48:e9a2c7cb57a4 | 187 | |
mbed_official | 48:e9a2c7cb57a4 | 188 | /* Memory pool for user specified stack allocation (+main, +timer) */ |
mbed_official | 48:e9a2c7cb57a4 | 189 | uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)]; |
mbed_official | 48:e9a2c7cb57a4 | 190 | uint32_t const os_stack_sz = sizeof(os_stack_mem); |
mbed_official | 85:ef0a22cdf839 | 191 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 192 | |
mbed_official | 48:e9a2c7cb57a4 | 193 | #ifndef OS_FIFOSZ |
mbed_official | 48:e9a2c7cb57a4 | 194 | #define OS_FIFOSZ 16 |
mbed_official | 48:e9a2c7cb57a4 | 195 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 196 | |
mbed_official | 48:e9a2c7cb57a4 | 197 | /* Fifo Queue buffer for ISR requests.*/ |
mbed_official | 48:e9a2c7cb57a4 | 198 | uint32_t os_fifo[OS_FIFOSZ*2+1]; |
mbed_official | 48:e9a2c7cb57a4 | 199 | uint8_t const os_fifo_size = OS_FIFOSZ; |
mbed_official | 48:e9a2c7cb57a4 | 200 | |
mbed_official | 48:e9a2c7cb57a4 | 201 | /* An array of Active task pointers. */ |
mbed_official | 48:e9a2c7cb57a4 | 202 | void *os_active_TCB[OS_TASK_CNT]; |
mbed_official | 48:e9a2c7cb57a4 | 203 | |
mbed_official | 48:e9a2c7cb57a4 | 204 | /* User Timers Resources */ |
mbed_official | 48:e9a2c7cb57a4 | 205 | #if (OS_TIMERS != 0) |
mbed_official | 48:e9a2c7cb57a4 | 206 | extern void osTimerThread (void const *argument); |
mbed_official | 85:ef0a22cdf839 | 207 | #ifdef __MBED_CMSIS_RTOS_CA9 |
mbed_official | 48:e9a2c7cb57a4 | 208 | osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ); |
mbed_official | 48:e9a2c7cb57a4 | 209 | #else |
mbed_official | 48:e9a2c7cb57a4 | 210 | osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ); |
mbed_official | 48:e9a2c7cb57a4 | 211 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 212 | osThreadId osThreadId_osTimerThread; |
mbed_official | 48:e9a2c7cb57a4 | 213 | osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *); |
mbed_official | 48:e9a2c7cb57a4 | 214 | osMessageQId osMessageQId_osTimerMessageQ; |
mbed_official | 48:e9a2c7cb57a4 | 215 | #else |
mbed_official | 48:e9a2c7cb57a4 | 216 | osThreadDef_t os_thread_def_osTimerThread = { NULL }; |
mbed_official | 48:e9a2c7cb57a4 | 217 | osThreadId osThreadId_osTimerThread; |
mbed_official | 48:e9a2c7cb57a4 | 218 | osMessageQDef(osTimerMessageQ, 0, void *); |
mbed_official | 48:e9a2c7cb57a4 | 219 | osMessageQId osMessageQId_osTimerMessageQ; |
mbed_official | 48:e9a2c7cb57a4 | 220 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 221 | |
mbed_official | 48:e9a2c7cb57a4 | 222 | /* Legacy RTX User Timers not used */ |
mbed_official | 68:d3d0e710b443 | 223 | uint32_t os_tmr = 0; |
mbed_official | 48:e9a2c7cb57a4 | 224 | uint32_t const *m_tmr = NULL; |
mbed_official | 48:e9a2c7cb57a4 | 225 | uint16_t const mp_tmr_size = 0; |
mbed_official | 48:e9a2c7cb57a4 | 226 | |
mbed_official | 48:e9a2c7cb57a4 | 227 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
mbed_official | 48:e9a2c7cb57a4 | 228 | /* A memory space for arm standard library. */ |
mbed_official | 48:e9a2c7cb57a4 | 229 | static uint32_t std_libspace[OS_TASK_CNT][96/4]; |
mbed_official | 48:e9a2c7cb57a4 | 230 | static OS_MUT std_libmutex[OS_MUTEXCNT]; |
mbed_official | 48:e9a2c7cb57a4 | 231 | static uint32_t nr_mutex; |
mbed_official | 48:e9a2c7cb57a4 | 232 | extern void *__libspace_start; |
mbed_official | 103:5a85840ab54e | 233 | #elif defined (__ICCARM__) |
mbed_official | 103:5a85840ab54e | 234 | typedef struct os_mut_array { |
mbed_official | 103:5a85840ab54e | 235 | OS_MUT mutex; |
mbed_official | 103:5a85840ab54e | 236 | uint32_t used; |
mbed_official | 103:5a85840ab54e | 237 | } os_mut_array_t; |
mbed_official | 103:5a85840ab54e | 238 | |
mbed_official | 103:5a85840ab54e | 239 | static os_mut_array_t std_libmutex[OS_MUTEXCNT];/* must be Zero clear */ |
mbed_official | 103:5a85840ab54e | 240 | static uint32_t nr_mutex = 0; |
mbed_official | 48:e9a2c7cb57a4 | 241 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 242 | |
mbed_official | 48:e9a2c7cb57a4 | 243 | |
mbed_official | 48:e9a2c7cb57a4 | 244 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 245 | * RTX Optimizations (empty functions) |
mbed_official | 48:e9a2c7cb57a4 | 246 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 247 | |
mbed_official | 48:e9a2c7cb57a4 | 248 | #if OS_ROBIN == 0 |
mbed_official | 48:e9a2c7cb57a4 | 249 | void rt_init_robin (void) {;} |
mbed_official | 48:e9a2c7cb57a4 | 250 | void rt_chk_robin (void) {;} |
mbed_official | 48:e9a2c7cb57a4 | 251 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 252 | |
mbed_official | 48:e9a2c7cb57a4 | 253 | #if OS_STKCHECK == 0 |
mbed_official | 48:e9a2c7cb57a4 | 254 | void rt_stk_check (void) {;} |
mbed_official | 48:e9a2c7cb57a4 | 255 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 256 | |
mbed_official | 48:e9a2c7cb57a4 | 257 | |
mbed_official | 48:e9a2c7cb57a4 | 258 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 259 | * Standard Library multithreading interface |
mbed_official | 48:e9a2c7cb57a4 | 260 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 261 | |
mbed_official | 48:e9a2c7cb57a4 | 262 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
mbed_official | 48:e9a2c7cb57a4 | 263 | |
mbed_official | 48:e9a2c7cb57a4 | 264 | /*--------------------------- __user_perthread_libspace ---------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 265 | |
mbed_official | 48:e9a2c7cb57a4 | 266 | void *__user_perthread_libspace (void) { |
mbed_official | 48:e9a2c7cb57a4 | 267 | /* Provide a separate libspace for each task. */ |
mbed_official | 48:e9a2c7cb57a4 | 268 | uint32_t idx; |
mbed_official | 48:e9a2c7cb57a4 | 269 | |
mbed_official | 48:e9a2c7cb57a4 | 270 | idx = runtask_id (); |
mbed_official | 48:e9a2c7cb57a4 | 271 | if (idx == 0) { |
mbed_official | 48:e9a2c7cb57a4 | 272 | /* RTX not running yet. */ |
mbed_official | 48:e9a2c7cb57a4 | 273 | return (&__libspace_start); |
mbed_official | 48:e9a2c7cb57a4 | 274 | } |
mbed_official | 48:e9a2c7cb57a4 | 275 | return ((void *)&std_libspace[idx-1]); |
mbed_official | 48:e9a2c7cb57a4 | 276 | } |
mbed_official | 48:e9a2c7cb57a4 | 277 | |
mbed_official | 48:e9a2c7cb57a4 | 278 | /*--------------------------- _mutex_initialize -----------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 279 | |
mbed_official | 48:e9a2c7cb57a4 | 280 | int _mutex_initialize (OS_ID *mutex) { |
mbed_official | 48:e9a2c7cb57a4 | 281 | /* Allocate and initialize a system mutex. */ |
mbed_official | 48:e9a2c7cb57a4 | 282 | |
mbed_official | 48:e9a2c7cb57a4 | 283 | if (nr_mutex >= OS_MUTEXCNT) { |
mbed_official | 48:e9a2c7cb57a4 | 284 | /* If you are here, you need to increase the number OS_MUTEXCNT. */ |
mbed_official | 48:e9a2c7cb57a4 | 285 | for (;;); |
mbed_official | 48:e9a2c7cb57a4 | 286 | } |
mbed_official | 48:e9a2c7cb57a4 | 287 | *mutex = &std_libmutex[nr_mutex++]; |
mbed_official | 48:e9a2c7cb57a4 | 288 | mutex_init (*mutex); |
mbed_official | 48:e9a2c7cb57a4 | 289 | return (1); |
mbed_official | 48:e9a2c7cb57a4 | 290 | } |
mbed_official | 48:e9a2c7cb57a4 | 291 | |
mbed_official | 48:e9a2c7cb57a4 | 292 | |
mbed_official | 48:e9a2c7cb57a4 | 293 | /*--------------------------- _mutex_acquire --------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 294 | |
mbed_official | 48:e9a2c7cb57a4 | 295 | __attribute__((used)) void _mutex_acquire (OS_ID *mutex) { |
mbed_official | 48:e9a2c7cb57a4 | 296 | /* Acquire a system mutex, lock stdlib resources. */ |
mbed_official | 48:e9a2c7cb57a4 | 297 | if (runtask_id ()) { |
mbed_official | 48:e9a2c7cb57a4 | 298 | /* RTX running, acquire a mutex. */ |
mbed_official | 48:e9a2c7cb57a4 | 299 | mutex_wait (*mutex); |
mbed_official | 48:e9a2c7cb57a4 | 300 | } |
mbed_official | 48:e9a2c7cb57a4 | 301 | } |
mbed_official | 48:e9a2c7cb57a4 | 302 | |
mbed_official | 48:e9a2c7cb57a4 | 303 | |
mbed_official | 48:e9a2c7cb57a4 | 304 | /*--------------------------- _mutex_release --------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 305 | |
mbed_official | 48:e9a2c7cb57a4 | 306 | __attribute__((used)) void _mutex_release (OS_ID *mutex) { |
mbed_official | 48:e9a2c7cb57a4 | 307 | /* Release a system mutex, unlock stdlib resources. */ |
mbed_official | 48:e9a2c7cb57a4 | 308 | if (runtask_id ()) { |
mbed_official | 48:e9a2c7cb57a4 | 309 | /* RTX running, release a mutex. */ |
mbed_official | 48:e9a2c7cb57a4 | 310 | mutex_rel (*mutex); |
mbed_official | 48:e9a2c7cb57a4 | 311 | } |
mbed_official | 48:e9a2c7cb57a4 | 312 | } |
mbed_official | 48:e9a2c7cb57a4 | 313 | |
mbed_official | 103:5a85840ab54e | 314 | #elif defined (__ICCARM__) |
mbed_official | 103:5a85840ab54e | 315 | |
mbed_official | 103:5a85840ab54e | 316 | /*--------------------------- __iar_system_Mtxinit --------------------------*/ |
mbed_official | 103:5a85840ab54e | 317 | |
mbed_official | 103:5a85840ab54e | 318 | void __iar_system_Mtxinit(__iar_Rmtx *mutex) |
mbed_official | 103:5a85840ab54e | 319 | { |
mbed_official | 103:5a85840ab54e | 320 | /* Allocate and initialize a system mutex. */ |
mbed_official | 103:5a85840ab54e | 321 | int32_t idx; |
mbed_official | 103:5a85840ab54e | 322 | |
mbed_official | 103:5a85840ab54e | 323 | for (idx = 0; idx < OS_MUTEXCNT; idx++) |
mbed_official | 103:5a85840ab54e | 324 | { |
mbed_official | 103:5a85840ab54e | 325 | if (std_libmutex[idx].used == 0) |
mbed_official | 103:5a85840ab54e | 326 | { |
mbed_official | 103:5a85840ab54e | 327 | std_libmutex[idx].used = 1; |
mbed_official | 103:5a85840ab54e | 328 | *mutex = &std_libmutex[idx].mutex; |
mbed_official | 103:5a85840ab54e | 329 | nr_mutex++; |
mbed_official | 103:5a85840ab54e | 330 | break; |
mbed_official | 103:5a85840ab54e | 331 | } |
mbed_official | 103:5a85840ab54e | 332 | } |
mbed_official | 103:5a85840ab54e | 333 | if (nr_mutex >= OS_MUTEXCNT) |
mbed_official | 103:5a85840ab54e | 334 | { |
mbed_official | 103:5a85840ab54e | 335 | /* If you are here, you need to increase the number OS_MUTEXCNT. */ |
mbed_official | 103:5a85840ab54e | 336 | for (;;); |
mbed_official | 103:5a85840ab54e | 337 | } |
mbed_official | 103:5a85840ab54e | 338 | |
mbed_official | 103:5a85840ab54e | 339 | mutex_init (*mutex); |
mbed_official | 103:5a85840ab54e | 340 | } |
mbed_official | 103:5a85840ab54e | 341 | |
mbed_official | 103:5a85840ab54e | 342 | /*--------------------------- __iar_system_Mtxdst ---------------------------*/ |
mbed_official | 103:5a85840ab54e | 343 | |
mbed_official | 103:5a85840ab54e | 344 | void __iar_system_Mtxdst(__iar_Rmtx *mutex) |
mbed_official | 103:5a85840ab54e | 345 | { |
mbed_official | 103:5a85840ab54e | 346 | /* Free a system mutex. */ |
mbed_official | 103:5a85840ab54e | 347 | int32_t idx; |
mbed_official | 103:5a85840ab54e | 348 | |
mbed_official | 103:5a85840ab54e | 349 | if (nr_mutex == 0) |
mbed_official | 103:5a85840ab54e | 350 | { |
mbed_official | 103:5a85840ab54e | 351 | for (;;); |
mbed_official | 103:5a85840ab54e | 352 | } |
mbed_official | 103:5a85840ab54e | 353 | |
mbed_official | 103:5a85840ab54e | 354 | idx = ((((uint32_t)mutex) - ((uint32_t)&std_libmutex[0].mutex)) |
mbed_official | 103:5a85840ab54e | 355 | / sizeof(os_mut_array_t)); |
mbed_official | 103:5a85840ab54e | 356 | |
mbed_official | 103:5a85840ab54e | 357 | if (idx >= OS_MUTEXCNT) |
mbed_official | 103:5a85840ab54e | 358 | { |
mbed_official | 103:5a85840ab54e | 359 | for (;;); |
mbed_official | 103:5a85840ab54e | 360 | } |
mbed_official | 103:5a85840ab54e | 361 | |
mbed_official | 103:5a85840ab54e | 362 | mutex_del (*mutex); |
mbed_official | 103:5a85840ab54e | 363 | std_libmutex[idx].used = 0; |
mbed_official | 103:5a85840ab54e | 364 | } |
mbed_official | 103:5a85840ab54e | 365 | |
mbed_official | 103:5a85840ab54e | 366 | /*--------------------------- __iar_system_Mtxlock --------------------------*/ |
mbed_official | 103:5a85840ab54e | 367 | |
mbed_official | 103:5a85840ab54e | 368 | void __iar_system_Mtxlock(__iar_Rmtx *mutex) |
mbed_official | 103:5a85840ab54e | 369 | { |
mbed_official | 103:5a85840ab54e | 370 | /* Acquire a system mutex, lock stdlib resources. */ |
mbed_official | 103:5a85840ab54e | 371 | if (runtask_id ()) |
mbed_official | 103:5a85840ab54e | 372 | { |
mbed_official | 103:5a85840ab54e | 373 | /* RTX running, acquire a mutex. */ |
mbed_official | 103:5a85840ab54e | 374 | mutex_wait (*mutex); |
mbed_official | 103:5a85840ab54e | 375 | } |
mbed_official | 103:5a85840ab54e | 376 | } |
mbed_official | 103:5a85840ab54e | 377 | |
mbed_official | 103:5a85840ab54e | 378 | /*--------------------------- __iar_system_Mtxunlock ------------------------*/ |
mbed_official | 103:5a85840ab54e | 379 | |
mbed_official | 103:5a85840ab54e | 380 | void __iar_system_Mtxunlock(__iar_Rmtx *mutex) |
mbed_official | 103:5a85840ab54e | 381 | { |
mbed_official | 103:5a85840ab54e | 382 | /* Release a system mutex, unlock stdlib resources. */ |
mbed_official | 103:5a85840ab54e | 383 | if (runtask_id ()) |
mbed_official | 103:5a85840ab54e | 384 | { |
mbed_official | 103:5a85840ab54e | 385 | /* RTX running, release a mutex. */ |
mbed_official | 103:5a85840ab54e | 386 | mutex_rel (*mutex); |
mbed_official | 103:5a85840ab54e | 387 | } |
mbed_official | 103:5a85840ab54e | 388 | } |
mbed_official | 103:5a85840ab54e | 389 | |
mbed_official | 48:e9a2c7cb57a4 | 390 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 391 | |
mbed_official | 48:e9a2c7cb57a4 | 392 | |
mbed_official | 48:e9a2c7cb57a4 | 393 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 394 | * RTX Startup |
mbed_official | 48:e9a2c7cb57a4 | 395 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 396 | |
mbed_official | 48:e9a2c7cb57a4 | 397 | /* Main Thread definition */ |
mbed_official | 48:e9a2c7cb57a4 | 398 | extern int main (void); |
mbed_official | 85:ef0a22cdf839 | 399 | #ifdef __MBED_CMSIS_RTOS_CA9 |
mbed_official | 85:ef0a22cdf839 | 400 | uint32_t os_thread_def_stack_main [(4 * OS_MAINSTKSIZE) / sizeof(uint32_t)]; |
mbed_official | 85:ef0a22cdf839 | 401 | osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE, os_thread_def_stack_main }; |
mbed_official | 85:ef0a22cdf839 | 402 | #else |
mbed_official | 48:e9a2c7cb57a4 | 403 | osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1, 4*OS_MAINSTKSIZE }; |
mbed_official | 85:ef0a22cdf839 | 404 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 405 | |
mbed_official | 48:e9a2c7cb57a4 | 406 | #if defined (__CC_ARM) |
mbed_official | 48:e9a2c7cb57a4 | 407 | |
mbed_official | 48:e9a2c7cb57a4 | 408 | #ifdef __MICROLIB |
mbed_official | 48:e9a2c7cb57a4 | 409 | void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); |
mbed_official | 48:e9a2c7cb57a4 | 410 | #if __TARGET_ARCH_ARM |
mbed_official | 48:e9a2c7cb57a4 | 411 | #pragma push |
mbed_official | 48:e9a2c7cb57a4 | 412 | #pragma arm |
mbed_official | 48:e9a2c7cb57a4 | 413 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 414 | void _main_init (void) { |
mbed_official | 48:e9a2c7cb57a4 | 415 | osKernelInitialize(); |
mbed_official | 48:e9a2c7cb57a4 | 416 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 48:e9a2c7cb57a4 | 417 | osKernelStart(); |
mbed_official | 48:e9a2c7cb57a4 | 418 | for (;;); |
mbed_official | 48:e9a2c7cb57a4 | 419 | } |
mbed_official | 48:e9a2c7cb57a4 | 420 | #if __TARGET_ARCH_ARM |
mbed_official | 48:e9a2c7cb57a4 | 421 | #pragma pop |
mbed_official | 48:e9a2c7cb57a4 | 422 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 423 | #else |
mbed_official | 48:e9a2c7cb57a4 | 424 | __asm void __rt_entry (void) { |
mbed_official | 48:e9a2c7cb57a4 | 425 | |
mbed_official | 48:e9a2c7cb57a4 | 426 | IMPORT __user_setup_stackheap |
mbed_official | 48:e9a2c7cb57a4 | 427 | IMPORT __rt_lib_init |
mbed_official | 48:e9a2c7cb57a4 | 428 | IMPORT os_thread_def_main |
mbed_official | 48:e9a2c7cb57a4 | 429 | IMPORT osKernelInitialize |
mbed_official | 48:e9a2c7cb57a4 | 430 | IMPORT osKernelStart |
mbed_official | 48:e9a2c7cb57a4 | 431 | IMPORT osThreadCreate |
mbed_official | 48:e9a2c7cb57a4 | 432 | IMPORT exit |
mbed_official | 48:e9a2c7cb57a4 | 433 | |
mbed_official | 48:e9a2c7cb57a4 | 434 | BL __user_setup_stackheap |
mbed_official | 48:e9a2c7cb57a4 | 435 | MOV R1,R2 |
mbed_official | 48:e9a2c7cb57a4 | 436 | BL __rt_lib_init |
mbed_official | 48:e9a2c7cb57a4 | 437 | BL osKernelInitialize |
mbed_official | 48:e9a2c7cb57a4 | 438 | LDR R0,=os_thread_def_main |
mbed_official | 48:e9a2c7cb57a4 | 439 | MOVS R1,#0 |
mbed_official | 48:e9a2c7cb57a4 | 440 | BL osThreadCreate |
mbed_official | 48:e9a2c7cb57a4 | 441 | BL osKernelStart |
mbed_official | 48:e9a2c7cb57a4 | 442 | BL exit |
mbed_official | 48:e9a2c7cb57a4 | 443 | |
mbed_official | 48:e9a2c7cb57a4 | 444 | ALIGN |
mbed_official | 48:e9a2c7cb57a4 | 445 | } |
mbed_official | 48:e9a2c7cb57a4 | 446 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 447 | |
mbed_official | 48:e9a2c7cb57a4 | 448 | #elif defined (__GNUC__) |
mbed_official | 48:e9a2c7cb57a4 | 449 | |
mbed_official | 48:e9a2c7cb57a4 | 450 | __attribute__((naked)) void software_init_hook (void) { |
mbed_official | 48:e9a2c7cb57a4 | 451 | __asm ( |
mbed_official | 48:e9a2c7cb57a4 | 452 | ".syntax unified\n" |
mbed_official | 67:63988a2238f7 | 453 | ".arm\n" |
mbed_official | 48:e9a2c7cb57a4 | 454 | "movs r0,#0\n" |
mbed_official | 48:e9a2c7cb57a4 | 455 | "movs r1,#0\n" |
mbed_official | 48:e9a2c7cb57a4 | 456 | "mov r4,r0\n" |
mbed_official | 48:e9a2c7cb57a4 | 457 | "mov r5,r1\n" |
mbed_official | 48:e9a2c7cb57a4 | 458 | "ldr r0,= __libc_fini_array\n" |
mbed_official | 48:e9a2c7cb57a4 | 459 | "bl atexit\n" |
mbed_official | 48:e9a2c7cb57a4 | 460 | "bl __libc_init_array\n" |
mbed_official | 48:e9a2c7cb57a4 | 461 | "mov r0,r4\n" |
mbed_official | 48:e9a2c7cb57a4 | 462 | "mov r1,r5\n" |
mbed_official | 48:e9a2c7cb57a4 | 463 | "bl osKernelInitialize\n" |
mbed_official | 48:e9a2c7cb57a4 | 464 | "ldr r0,=os_thread_def_main\n" |
mbed_official | 48:e9a2c7cb57a4 | 465 | "movs r1,#0\n" |
mbed_official | 48:e9a2c7cb57a4 | 466 | "bl osThreadCreate\n" |
mbed_official | 48:e9a2c7cb57a4 | 467 | "bl osKernelStart\n" |
mbed_official | 48:e9a2c7cb57a4 | 468 | "bl exit\n" |
mbed_official | 48:e9a2c7cb57a4 | 469 | ); |
mbed_official | 48:e9a2c7cb57a4 | 470 | } |
mbed_official | 48:e9a2c7cb57a4 | 471 | |
mbed_official | 48:e9a2c7cb57a4 | 472 | #elif defined (__ICCARM__) |
mbed_official | 48:e9a2c7cb57a4 | 473 | |
mbed_official | 48:e9a2c7cb57a4 | 474 | extern void exit(int arg); |
mbed_official | 48:e9a2c7cb57a4 | 475 | |
mbed_official | 103:5a85840ab54e | 476 | void mbed_main(void) { |
mbed_official | 48:e9a2c7cb57a4 | 477 | int a; |
mbed_official | 68:d3d0e710b443 | 478 | |
mbed_official | 48:e9a2c7cb57a4 | 479 | osKernelInitialize(); |
mbed_official | 48:e9a2c7cb57a4 | 480 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 48:e9a2c7cb57a4 | 481 | a = osKernelStart(); |
mbed_official | 48:e9a2c7cb57a4 | 482 | exit(a); |
mbed_official | 48:e9a2c7cb57a4 | 483 | } |
mbed_official | 48:e9a2c7cb57a4 | 484 | |
mbed_official | 48:e9a2c7cb57a4 | 485 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 486 | |
mbed_official | 48:e9a2c7cb57a4 | 487 | |
mbed_official | 48:e9a2c7cb57a4 | 488 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 489 | * end of file |
mbed_official | 48:e9a2c7cb57a4 | 490 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 491 |