1
1
/*----------------------------------------------------------------------------
2
- * RL-ARM - RTX
2
+ * CMSIS-RTOS - RTX
3
3
*----------------------------------------------------------------------------
4
4
* Name: RTX_CM_LIB.H
5
5
* Purpose: RTX Kernel System Configuration
6
- * Rev.: V4.73
6
+ * Rev.: V4.79
7
7
*----------------------------------------------------------------------------
8
8
*
9
- * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
9
+ * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
10
10
* All rights reserved.
11
11
* Redistribution and use in source and binary forms, with or without
12
12
* modification, are permitted provided that the following conditions are met:
15
15
* - Redistributions in binary form must reproduce the above copyright
16
16
* notice, this list of conditions and the following disclaimer in the
17
17
* documentation and/or other materials provided with the distribution.
18
- * - Neither the name of ARM nor the names of its contributors may be used
19
- * to endorse or promote products derived from this software without
18
+ * - Neither the name of ARM nor the names of its contributors may be used
19
+ * to endorse or promote products derived from this software without
20
20
* specific prior written permission.
21
21
*
22
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
25
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26
26
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
31
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
32
* POSSIBILITY OF SUCH DAMAGE.
33
33
*---------------------------------------------------------------------------*/
@@ -63,9 +63,10 @@ typedef uint32_t OS_RESULT;
63
63
64
64
#define runtask_id () rt_tsk_self()
65
65
#define mutex_init (m ) rt_mut_init(m)
66
- #define mutex_wait (m ) os_mut_wait(m,0xFFFF )
66
+ #define mutex_wait (m ) os_mut_wait(m,0xFFFFU )
67
67
#define mutex_rel (m ) os_mut_release(m)
68
68
69
+ extern uint8_t os_running ;
69
70
extern OS_TID rt_tsk_self (void );
70
71
extern void rt_mut_init (OS_ID mutex );
71
72
extern OS_RESULT rt_mut_release (OS_ID mutex );
@@ -140,6 +141,14 @@ void __iar_system_Mtxunlock(__iar_Rmtx *);
140
141
* Global Variables
141
142
*---------------------------------------------------------------------------*/
142
143
144
+ #if (OS_TASKCNT == 0 )
145
+ #error "Invalid number of concurrent running threads!"
146
+ #endif
147
+
148
+ #if (OS_PRIVCNT >= OS_TASKCNT )
149
+ #error "Too many threads with user-provided stack size!"
150
+ #endif
151
+
143
152
#if (OS_TIMERS != 0 )
144
153
#define OS_TASK_CNT (OS_TASKCNT + 1)
145
154
#ifndef __MBED_CMSIS_RTOS_CA9
@@ -154,24 +163,32 @@ void __iar_system_Mtxunlock(__iar_Rmtx *);
154
163
#endif
155
164
#endif
156
165
166
+ #ifndef OS_STKINIT
167
+ #define OS_STKINIT 0
168
+ #endif
169
+
157
170
uint16_t const os_maxtaskrun = OS_TASK_CNT ;
158
171
#ifdef __MBED_CMSIS_RTOS_CA9
159
- uint32_t const os_stackinfo = (OS_STKCHECK <<24 )| (OS_IDLESTKSIZE * 4 );
172
+ uint32_t const os_stackinfo = (OS_STKINIT << 28 ) | ( OS_STKCHECK <<24 ) | (OS_IDLESTKSIZE * 4 );
160
173
#else
161
- uint32_t const os_stackinfo = (OS_STKCHECK <<24 )| (OS_PRIV_CNT <<16 ) | (OS_STKSIZE * 4 );
174
+ uint32_t const os_stackinfo = (OS_STKINIT << 28 ) | ( OS_STKCHECK <<24 ) | (OS_PRIV_CNT <<16 ) | (OS_STKSIZE * 4 );
162
175
#endif
163
176
uint32_t const os_rrobin = (OS_ROBIN << 16 ) | OS_ROBINTOUT ;
164
177
uint32_t const os_tickfreq = OS_CLOCK ;
165
178
uint16_t const os_tickus_i = OS_CLOCK /1000000 ;
166
179
uint16_t const os_tickus_f = (((uint64_t )(OS_CLOCK - 1000000 * (OS_CLOCK /1000000 )))<<16 )/1000000 ;
167
180
uint32_t const os_trv = OS_TRV ;
181
+ #if defined(FEATURE_UVISOR ) && defined(TARGET_UVISOR_SUPPORTED )
182
+ uint8_t const os_flags = 0 ;
183
+ #else /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
168
184
uint8_t const os_flags = OS_RUNPRIV ;
185
+ #endif /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
169
186
170
187
/* Export following defines to uVision debugger. */
171
188
__USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS ;
172
189
__USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX ;
173
190
__USED uint32_t const os_clockrate = OS_TICK ;
174
- __USED uint32_t const os_timernum = 0 ;
191
+ __USED uint32_t const os_timernum = 0U ;
175
192
176
193
/* Memory pool for TCB allocation */
177
194
_declare_box (mp_tcb , OS_TCB_SIZE , OS_TASK_CNT );
@@ -216,14 +233,14 @@ osMessageQId osMessageQId_osTimerMessageQ;
216
233
#else
217
234
osThreadDef_t os_thread_def_osTimerThread = { NULL };
218
235
osThreadId osThreadId_osTimerThread ;
219
- osMessageQDef (osTimerMessageQ , 0 , void * );
236
+ osMessageQDef (osTimerMessageQ , 0U , void * );
220
237
osMessageQId osMessageQId_osTimerMessageQ ;
221
238
#endif
222
239
223
240
/* Legacy RTX User Timers not used */
224
- uint32_t os_tmr = 0 ;
241
+ uint32_t os_tmr = 0U ;
225
242
uint32_t const * m_tmr = NULL ;
226
- uint16_t const mp_tmr_size = 0 ;
243
+ uint16_t const mp_tmr_size = 0U ;
227
244
228
245
/* singleton mutex */
229
246
osMutexId singleton_mutex_id ;
@@ -272,8 +289,8 @@ void *__user_perthread_libspace (void) {
272
289
/* Provide a separate libspace for each task. */
273
290
uint32_t idx ;
274
291
275
- idx = runtask_id ();
276
- if (idx == 0 ) {
292
+ idx = ( os_running != 0U ) ? runtask_id () : 0U ;
293
+ if (idx == 0U ) {
277
294
/* RTX not running yet. */
278
295
return (& __libspace_start );
279
296
}
@@ -299,7 +316,7 @@ int _mutex_initialize (OS_ID *mutex) {
299
316
300
317
__attribute__((used )) void _mutex_acquire (OS_ID * mutex ) {
301
318
/* Acquire a system mutex, lock stdlib resources. */
302
- if (runtask_id () ) {
319
+ if (os_running ) {
303
320
/* RTX running, acquire a mutex. */
304
321
mutex_wait (* mutex );
305
322
}
@@ -310,7 +327,7 @@ __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
310
327
311
328
__attribute__((used )) void _mutex_release (OS_ID * mutex ) {
312
329
/* Release a system mutex, unlock stdlib resources. */
313
- if (runtask_id () ) {
330
+ if (os_running ) {
314
331
/* RTX running, release a mutex. */
315
332
mutex_rel (* mutex );
316
333
}
@@ -403,9 +420,9 @@ void __iar_system_Mtxunlock(__iar_Rmtx *mutex)
403
420
extern void pre_main (void );
404
421
#ifdef __MBED_CMSIS_RTOS_CA9
405
422
uint32_t os_thread_def_stack_main [(4 * OS_MAINSTKSIZE ) / sizeof (uint32_t )];
406
- osThreadDef_t os_thread_def_main = {(os_pthread )pre_main , osPriorityNormal , 1 , 4 * OS_MAINSTKSIZE , os_thread_def_stack_main };
423
+ osThreadDef_t os_thread_def_main = {(os_pthread )pre_main , osPriorityNormal , 1U , 4 * OS_MAINSTKSIZE , os_thread_def_stack_main };
407
424
#else
408
- osThreadDef_t os_thread_def_main = {(os_pthread )pre_main , osPriorityNormal , 1 , 4 * OS_MAINSTKSIZE };
425
+ osThreadDef_t os_thread_def_main = {(os_pthread )pre_main , osPriorityNormal , 1U , 4 * OS_MAINSTKSIZE };
409
426
#endif
410
427
411
428
#if defined (__CC_ARM )
@@ -485,14 +502,21 @@ __asm void __rt_entry (void) {
485
502
#endif
486
503
487
504
#elif defined (__GNUC__ )
505
+
506
+ osMutexDef (malloc_mutex );
507
+ static osMutexId malloc_mutex_id ;
508
+ osMutexDef (env_mutex );
509
+ static osMutexId env_mutex_id ;
510
+
488
511
extern int atexit (void (* func )(void ));
489
512
extern void __libc_fini_array (void );
490
513
extern void __libc_init_array (void );
491
514
extern int main (int argc , char * * argv );
492
515
493
516
void pre_main (void ) {
494
517
singleton_mutex_id = osMutexCreate (osMutex (singleton_mutex ));
495
- atexit (__libc_fini_array );
518
+ malloc_mutex_id = osMutexCreate (osMutex (malloc_mutex ));
519
+ env_mutex_id = osMutexCreate (osMutex (env_mutex ));
496
520
__libc_init_array ();
497
521
main (0 , NULL );
498
522
}
@@ -511,6 +535,29 @@ __attribute__((naked)) void software_init_hook_rtos (void) {
511
535
);
512
536
}
513
537
538
+ // Opaque declaration of _reent structure
539
+ struct _reent ;
540
+
541
+ void __rtos_malloc_lock ( struct _reent * _r )
542
+ {
543
+ osMutexWait (malloc_mutex_id , osWaitForever );
544
+ }
545
+
546
+ void __rtos_malloc_unlock ( struct _reent * _r )
547
+ {
548
+ osMutexRelease (malloc_mutex_id );
549
+ }
550
+
551
+ void __rtos_env_lock ( struct _reent * _r )
552
+ {
553
+ osMutexWait (env_mutex_id , osWaitForever );
554
+ }
555
+
556
+ void __rtos_env_unlock ( struct _reent * _r )
557
+ {
558
+ osMutexRelease (env_mutex_id );
559
+ }
560
+
514
561
#elif defined (__ICCARM__)
515
562
extern void * __vector_core_a9 ;
516
563
extern int __low_level_init (void );
@@ -533,7 +580,7 @@ void pre_main(void) {
533
580
}
534
581
535
582
#pragma required=__vector_core_a9
536
- void __iar_program_start ( void )
583
+ void __iar_program_start (void )
537
584
{
538
585
__iar_init_core ();
539
586
__iar_init_vfp ();
@@ -556,8 +603,6 @@ void __iar_program_start( void )
556
603
557
604
#endif
558
605
559
-
560
606
/*----------------------------------------------------------------------------
561
607
* end of file
562
608
*---------------------------------------------------------------------------*/
563
-
0 commit comments