Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more

Deprecated

This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.

Committer:
Kojto
Date:
Tue Jul 04 13:32:20 2017 +0100
Revision:
125:5713cbbdb706
Parent:
123:58563e6cba1e
replace mbed_rtx by mbed_rtx4

Not causing a conflict with mbed_rtx that is for newer rtos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 49:77c8e4604045 1 /*----------------------------------------------------------------------------
mbed_official 112:53ace74b190c 2 * CMSIS-RTOS - RTX
mbed_official 49:77c8e4604045 3 *----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 4 * Name: RTX_Conf_CM.C
mbed_official 49:77c8e4604045 5 * Purpose: Configuration of CMSIS RTX Kernel for Cortex-M
mbed_official 112:53ace74b190c 6 * Rev.: V4.70.1
mbed_official 49:77c8e4604045 7 *----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 8 *
mbed_official 112:53ace74b190c 9 * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
mbed_official 49:77c8e4604045 10 * All rights reserved.
mbed_official 49:77c8e4604045 11 * Redistribution and use in source and binary forms, with or without
mbed_official 49:77c8e4604045 12 * modification, are permitted provided that the following conditions are met:
mbed_official 49:77c8e4604045 13 * - Redistributions of source code must retain the above copyright
mbed_official 49:77c8e4604045 14 * notice, this list of conditions and the following disclaimer.
mbed_official 49:77c8e4604045 15 * - Redistributions in binary form must reproduce the above copyright
mbed_official 49:77c8e4604045 16 * notice, this list of conditions and the following disclaimer in the
mbed_official 49:77c8e4604045 17 * documentation and/or other materials provided with the distribution.
mbed_official 49:77c8e4604045 18 * - Neither the name of ARM nor the names of its contributors may be used
mbed_official 49:77c8e4604045 19 * to endorse or promote products derived from this software without
mbed_official 49:77c8e4604045 20 * specific prior written permission.
mbed_official 49:77c8e4604045 21 *
mbed_official 49:77c8e4604045 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 49:77c8e4604045 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 49:77c8e4604045 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbed_official 49:77c8e4604045 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbed_official 49:77c8e4604045 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbed_official 49:77c8e4604045 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbed_official 49:77c8e4604045 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 49:77c8e4604045 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 49:77c8e4604045 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbed_official 49:77c8e4604045 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 49:77c8e4604045 32 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 49:77c8e4604045 33 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 34
mbed_official 49:77c8e4604045 35 #include "cmsis_os.h"
mbed_official 49:77c8e4604045 36
mbed_official 49:77c8e4604045 37
mbed_official 49:77c8e4604045 38 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 39 * RTX User configuration part BEGIN
mbed_official 49:77c8e4604045 40 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 41
c1728p9 123:58563e6cba1e 42 // Include per-target RTX config file
Kojto 125:5713cbbdb706 43 #include "mbed_rtx4.h"
c1728p9 123:58563e6cba1e 44
mbed_official 49:77c8e4604045 45 //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
mbed_official 49:77c8e4604045 46 //
mbed_official 49:77c8e4604045 47 // <h>Thread Configuration
mbed_official 49:77c8e4604045 48 // =======================
mbed_official 49:77c8e4604045 49 //
mbed_official 112:53ace74b190c 50 // <o>Number of concurrent running user threads <1-250>
mbed_official 112:53ace74b190c 51 // <i> Defines max. number of user threads that will run at the same time.
mbed_official 49:77c8e4604045 52 // <i> Default: 6
mbed_official 49:77c8e4604045 53 #ifndef OS_TASKCNT
c1728p9 123:58563e6cba1e 54 #error "no target defined"
mbed_official 49:77c8e4604045 55 #endif
mbed_official 49:77c8e4604045 56
mbed_official 112:53ace74b190c 57 #ifdef __MBED_CMSIS_RTOS_CM
mbed_official 112:53ace74b190c 58 // <o>Idle stack size [bytes] <64-4096:8><#/4>
mbed_official 112:53ace74b190c 59 // <i> Defines default stack size for the Idle thread.
mbed_official 112:53ace74b190c 60 #ifndef OS_IDLESTKSIZE
mbed_official 112:53ace74b190c 61 #define OS_IDLESTKSIZE 128
mbed_official 112:53ace74b190c 62 #endif
mbed_official 112:53ace74b190c 63 #else // __MBED_CMSIS_RTOS_CM
mbed_official 112:53ace74b190c 64 // <o>Default Thread stack size [bytes] <64-4096:8><#/4>
mbed_official 112:53ace74b190c 65 // <i> Defines default stack size for threads with osThreadDef stacksz = 0
mbed_official 112:53ace74b190c 66 // <i> Default: 200
mbed_official 112:53ace74b190c 67 #ifndef OS_STKSIZE
mbed_official 112:53ace74b190c 68 #define OS_STKSIZE 200
mbed_official 112:53ace74b190c 69 #endif
mbed_official 112:53ace74b190c 70 #endif // __MBED_CMSIS_RTOS_CM
mbed_official 112:53ace74b190c 71
mbed_official 112:53ace74b190c 72 // <o>Main Thread stack size [bytes] <64-32768:8><#/4>
mbed_official 112:53ace74b190c 73 #ifndef OS_MAINSTKSIZE
c1728p9 123:58563e6cba1e 74 #error "no target defined"
mbed_official 49:77c8e4604045 75 #endif
mbed_official 49:77c8e4604045 76
mbed_official 112:53ace74b190c 77 #ifndef __MBED_CMSIS_RTOS_CM
mbed_official 112:53ace74b190c 78 // <o>Number of threads with user-provided stack size <0-250>
mbed_official 112:53ace74b190c 79 // <i> Defines the number of threads with user-provided stack size.
mbed_official 112:53ace74b190c 80 // <i> Default: 0
mbed_official 112:53ace74b190c 81 #ifndef OS_PRIVCNT
mbed_official 112:53ace74b190c 82 #define OS_PRIVCNT 0
mbed_official 49:77c8e4604045 83 #endif
Kojto 118:6635230e06ba 84
mbed_official 112:53ace74b190c 85 // <o>Total stack size [bytes] for threads with user-provided stack size <0-1048576:8><#/4>
mbed_official 112:53ace74b190c 86 // <i> Defines the combined stack size for threads with user-provided stack size.
mbed_official 112:53ace74b190c 87 // <i> Default: 0
mbed_official 112:53ace74b190c 88 #ifndef OS_PRIVSTKSIZE
mbed_official 112:53ace74b190c 89 #define OS_PRIVSTKSIZE 0 // this stack size value is in words
mbed_official 112:53ace74b190c 90 #endif
mbed_official 112:53ace74b190c 91 #endif // __MBED_CMSIS_RTOS_CM
mbed_official 49:77c8e4604045 92
mbed_official 112:53ace74b190c 93 // <q>Stack overflow checking
mbed_official 112:53ace74b190c 94 // <i> Enable stack overflow checks at thread switch.
mbed_official 112:53ace74b190c 95 // <i> Enabling this option increases slightly the execution time of a thread switch.
mbed_official 49:77c8e4604045 96 #ifndef OS_STKCHECK
mbed_official 49:77c8e4604045 97 #define OS_STKCHECK 1
mbed_official 49:77c8e4604045 98 #endif
Kojto 118:6635230e06ba 99
mbed_official 112:53ace74b190c 100 // <q>Stack usage watermark
mbed_official 112:53ace74b190c 101 // <i> Initialize thread stack with watermark pattern for analyzing stack usage (current/maximum) in System and Thread Viewer.
mbed_official 112:53ace74b190c 102 // <i> Enabling this option increases significantly the execution time of osThreadCreate.
mbed_official 112:53ace74b190c 103 #ifndef OS_STKINIT
c1728p9 123:58563e6cba1e 104 #if (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED)
c1728p9 123:58563e6cba1e 105 #define OS_STKINIT 1
c1728p9 123:58563e6cba1e 106 #else
c1728p9 123:58563e6cba1e 107 #define OS_STKINIT 0
c1728p9 123:58563e6cba1e 108 #endif
mbed_official 112:53ace74b190c 109 #endif
Kojto 118:6635230e06ba 110
Kojto 118:6635230e06ba 111 // <o>Processor mode for thread execution
Kojto 118:6635230e06ba 112 // <0=> Unprivileged mode
mbed_official 112:53ace74b190c 113 // <1=> Privileged mode
mbed_official 112:53ace74b190c 114 // <i> Default: Privileged mode
mbed_official 49:77c8e4604045 115 #ifndef OS_RUNPRIV
mbed_official 49:77c8e4604045 116 #define OS_RUNPRIV 1
mbed_official 49:77c8e4604045 117 #endif
mbed_official 49:77c8e4604045 118
mbed_official 49:77c8e4604045 119 // </h>
Kojto 118:6635230e06ba 120
mbed_official 112:53ace74b190c 121 // <h>RTX Kernel Timer Tick Configuration
mbed_official 112:53ace74b190c 122 // ======================================
mbed_official 112:53ace74b190c 123 // <q> Use Cortex-M SysTick timer as RTX Kernel Timer
Kojto 118:6635230e06ba 124 // <i> Cortex-M processors provide in most cases a SysTick timer that can be used as
mbed_official 112:53ace74b190c 125 // <i> as time-base for RTX.
mbed_official 112:53ace74b190c 126 #ifndef OS_SYSTICK
c1728p9 123:58563e6cba1e 127 #define OS_SYSTICK 1
mbed_official 112:53ace74b190c 128 #endif
mbed_official 49:77c8e4604045 129 //
mbed_official 112:53ace74b190c 130 // <o>RTOS Kernel Timer input clock frequency [Hz] <1-1000000000>
Kojto 118:6635230e06ba 131 // <i> Defines the input frequency of the RTOS Kernel Timer.
Kojto 118:6635230e06ba 132 // <i> When the Cortex-M SysTick timer is used, the input clock
mbed_official 112:53ace74b190c 133 // <i> is on most systems identical with the core clock.
mbed_official 49:77c8e4604045 134 #ifndef OS_CLOCK
c1728p9 123:58563e6cba1e 135 #error "no target defined"
mbed_official 49:77c8e4604045 136 #endif
Kojto 118:6635230e06ba 137
mbed_official 112:53ace74b190c 138 // <o>RTX Timer tick interval value [us] <1-1000000>
mbed_official 112:53ace74b190c 139 // <i> The RTX Timer tick interval value is used to calculate timeout values.
mbed_official 112:53ace74b190c 140 // <i> When the Cortex-M SysTick timer is enabled, the value also configures the SysTick timer.
mbed_official 49:77c8e4604045 141 // <i> Default: 1000 (1ms)
mbed_official 49:77c8e4604045 142 #ifndef OS_TICK
mbed_official 49:77c8e4604045 143 #define OS_TICK 1000
mbed_official 49:77c8e4604045 144 #endif
mbed_official 49:77c8e4604045 145
mbed_official 49:77c8e4604045 146 // </h>
mbed_official 49:77c8e4604045 147
mbed_official 49:77c8e4604045 148 // <h>System Configuration
mbed_official 49:77c8e4604045 149 // =======================
mbed_official 49:77c8e4604045 150 //
mbed_official 49:77c8e4604045 151 // <e>Round-Robin Thread switching
mbed_official 49:77c8e4604045 152 // ===============================
mbed_official 49:77c8e4604045 153 //
mbed_official 49:77c8e4604045 154 // <i> Enables Round-Robin Thread switching.
mbed_official 49:77c8e4604045 155 #ifndef OS_ROBIN
mbed_official 49:77c8e4604045 156 #define OS_ROBIN 1
mbed_official 49:77c8e4604045 157 #endif
mbed_official 49:77c8e4604045 158
mbed_official 49:77c8e4604045 159 // <o>Round-Robin Timeout [ticks] <1-1000>
mbed_official 49:77c8e4604045 160 // <i> Defines how long a thread will execute before a thread switch.
mbed_official 49:77c8e4604045 161 // <i> Default: 5
mbed_official 49:77c8e4604045 162 #ifndef OS_ROBINTOUT
mbed_official 49:77c8e4604045 163 #define OS_ROBINTOUT 5
mbed_official 49:77c8e4604045 164 #endif
mbed_official 49:77c8e4604045 165
mbed_official 49:77c8e4604045 166 // </e>
mbed_official 49:77c8e4604045 167
mbed_official 49:77c8e4604045 168 // <e>User Timers
mbed_official 49:77c8e4604045 169 // ==============
mbed_official 49:77c8e4604045 170 // <i> Enables user Timers
mbed_official 49:77c8e4604045 171 #ifndef OS_TIMERS
mbed_official 49:77c8e4604045 172 #define OS_TIMERS 1
mbed_official 49:77c8e4604045 173 #endif
mbed_official 49:77c8e4604045 174
mbed_official 49:77c8e4604045 175 // <o>Timer Thread Priority
mbed_official 49:77c8e4604045 176 // <1=> Low
mbed_official 112:53ace74b190c 177 // <2=> Below Normal <3=> Normal <4=> Above Normal
mbed_official 49:77c8e4604045 178 // <5=> High
mbed_official 49:77c8e4604045 179 // <6=> Realtime (highest)
mbed_official 49:77c8e4604045 180 // <i> Defines priority for Timer Thread
mbed_official 49:77c8e4604045 181 // <i> Default: High
mbed_official 49:77c8e4604045 182 #ifndef OS_TIMERPRIO
mbed_official 49:77c8e4604045 183 #define OS_TIMERPRIO 5
mbed_official 49:77c8e4604045 184 #endif
Kojto 118:6635230e06ba 185
mbed_official 112:53ace74b190c 186 // <o>Timer Thread stack size [bytes] <64-4096:8><#/4>
mbed_official 112:53ace74b190c 187 // <i> Defines stack size for Timer thread.
mbed_official 112:53ace74b190c 188 // <i> Default: 200
mbed_official 112:53ace74b190c 189 #ifndef OS_TIMERSTKSZ
mbed_official 112:53ace74b190c 190 #define OS_TIMERSTKSZ 200
mbed_official 112:53ace74b190c 191 #endif
Kojto 118:6635230e06ba 192
mbed_official 49:77c8e4604045 193 // <o>Timer Callback Queue size <1-32>
mbed_official 49:77c8e4604045 194 // <i> Number of concurrent active timer callback functions.
mbed_official 49:77c8e4604045 195 // <i> Default: 4
mbed_official 112:53ace74b190c 196 #ifndef OS_TIMERCBQS
mbed_official 49:77c8e4604045 197 #define OS_TIMERCBQS 4
mbed_official 49:77c8e4604045 198 #endif
mbed_official 49:77c8e4604045 199
mbed_official 49:77c8e4604045 200 // </e>
mbed_official 49:77c8e4604045 201
mbed_official 49:77c8e4604045 202 // <o>ISR FIFO Queue size<4=> 4 entries <8=> 8 entries
mbed_official 49:77c8e4604045 203 // <12=> 12 entries <16=> 16 entries
mbed_official 49:77c8e4604045 204 // <24=> 24 entries <32=> 32 entries
mbed_official 49:77c8e4604045 205 // <48=> 48 entries <64=> 64 entries
mbed_official 49:77c8e4604045 206 // <96=> 96 entries
mbed_official 49:77c8e4604045 207 // <i> ISR functions store requests to this buffer,
mbed_official 49:77c8e4604045 208 // <i> when they are called from the interrupt handler.
mbed_official 49:77c8e4604045 209 // <i> Default: 16 entries
mbed_official 49:77c8e4604045 210 #ifndef OS_FIFOSZ
mbed_official 49:77c8e4604045 211 #define OS_FIFOSZ 16
mbed_official 49:77c8e4604045 212 #endif
mbed_official 49:77c8e4604045 213
mbed_official 49:77c8e4604045 214 // </h>
mbed_official 49:77c8e4604045 215
mbed_official 49:77c8e4604045 216 //------------- <<< end of configuration section >>> -----------------------
mbed_official 49:77c8e4604045 217
mbed_official 49:77c8e4604045 218 // Standard library system mutexes
mbed_official 49:77c8e4604045 219 // ===============================
mbed_official 49:77c8e4604045 220 // Define max. number system mutexes that are used to protect
mbed_official 49:77c8e4604045 221 // the arm standard runtime library. For microlib they are not used.
mbed_official 49:77c8e4604045 222 #ifndef OS_MUTEXCNT
mbed_official 49:77c8e4604045 223 #define OS_MUTEXCNT 12
mbed_official 49:77c8e4604045 224 #endif
mbed_official 49:77c8e4604045 225
mbed_official 49:77c8e4604045 226 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 227 * RTX User configuration part END
mbed_official 49:77c8e4604045 228 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 229
mbed_official 49:77c8e4604045 230 #define OS_TRV ((uint32_t)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
mbed_official 49:77c8e4604045 231
mbed_official 49:77c8e4604045 232
mbed_official 49:77c8e4604045 233 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 234 * OS Idle daemon
mbed_official 49:77c8e4604045 235 *---------------------------------------------------------------------------*/
mbed_official 107:bdd541595fc5 236 extern void rtos_idle_loop(void);
mbed_official 49:77c8e4604045 237
mbed_official 107:bdd541595fc5 238 void os_idle_demon (void) {
mbed_official 107:bdd541595fc5 239 /* The idle demon is a system thread, running when no other thread is */
mbed_official 107:bdd541595fc5 240 /* ready to run. */
mbed_official 107:bdd541595fc5 241 rtos_idle_loop();
mbed_official 49:77c8e4604045 242 }
mbed_official 49:77c8e4604045 243
mbed_official 49:77c8e4604045 244 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 245 * RTX Errors
mbed_official 49:77c8e4604045 246 *---------------------------------------------------------------------------*/
mbed_official 112:53ace74b190c 247 extern void error(const char* format, ...);
mbed_official 112:53ace74b190c 248 extern osThreadId svcThreadGetId (void);
mbed_official 112:53ace74b190c 249
mbed_official 49:77c8e4604045 250 void os_error (uint32_t err_code) {
mbed_official 49:77c8e4604045 251 /* This function is called when a runtime error is detected. Parameter */
mbed_official 112:53ace74b190c 252 /* 'err_code' holds the runtime error code (defined in RTX_Config.h). */
mbed_official 112:53ace74b190c 253 osThreadId err_task = svcThreadGetId();
mbed_official 113:d9366c711a75 254 error("RTX error code: 0x%08X, task ID: 0x%08X\n", err_code, err_task);
mbed_official 49:77c8e4604045 255 }
mbed_official 49:77c8e4604045 256
mbed_official 49:77c8e4604045 257 void sysThreadError(osStatus status) {
mbed_official 49:77c8e4604045 258 if (status != osOK) {
mbed_official 113:d9366c711a75 259 osThreadId err_task = svcThreadGetId();
mbed_official 113:d9366c711a75 260 error("CMSIS-RTOS error status: 0x%08X, task ID: 0x%08X\n", status, err_task);
mbed_official 49:77c8e4604045 261 }
mbed_official 49:77c8e4604045 262 }
mbed_official 49:77c8e4604045 263
mbed_official 49:77c8e4604045 264 /*----------------------------------------------------------------------------
c1728p9 123:58563e6cba1e 265 * RTX Hooks
c1728p9 123:58563e6cba1e 266 *---------------------------------------------------------------------------*/
c1728p9 123:58563e6cba1e 267 extern void thread_terminate_hook(osThreadId id);
c1728p9 123:58563e6cba1e 268
c1728p9 123:58563e6cba1e 269 void sysThreadTerminate(osThreadId id) {
c1728p9 123:58563e6cba1e 270 thread_terminate_hook(id);
c1728p9 123:58563e6cba1e 271 }
c1728p9 123:58563e6cba1e 272
c1728p9 123:58563e6cba1e 273 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 274 * RTX Configuration Functions
mbed_official 49:77c8e4604045 275 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 276
mbed_official 49:77c8e4604045 277 #include "RTX_CM_lib.h"
mbed_official 49:77c8e4604045 278
mbed_official 49:77c8e4604045 279 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 280 * end of file
mbed_official 49:77c8e4604045 281 *---------------------------------------------------------------------------*/