54
54
#define OS_TCB_SIZE 52
55
55
#define OS_TMR_SIZE 8
56
56
57
- #if defined (__CC_ARM ) && !defined (__MICROLIB )
58
-
59
57
typedef void * OS_ID ;
60
58
typedef uint32_t OS_TID ;
61
59
typedef uint32_t OS_MUT [4 ];
62
60
typedef uint32_t OS_RESULT ;
63
61
62
+ #if defined (__CC_ARM ) && !defined (__MICROLIB )
63
+
64
64
#define runtask_id () rt_tsk_self()
65
65
#define mutex_init (m ) rt_mut_init(m)
66
66
#define mutex_wait (m ) os_mut_wait(m,0xFFFFU)
@@ -190,6 +190,77 @@ uint16_t const mp_tmr_size = 0U;
190
190
extern void * __libspace_start ;
191
191
#endif
192
192
193
+ #if defined (__ICCARM__ )
194
+ static osMutexId std_mutex_id_sys [_MAX_LOCK ] = {0 };
195
+ static OS_MUT std_mutex_sys [_MAX_LOCK ] = {0 };
196
+ #define _FOPEN_MAX 10
197
+ static osMutexId std_mutex_id_file [_FOPEN_MAX ] = {0 };
198
+ static OS_MUT std_mutex_file [_FOPEN_MAX ] = {0 };
199
+ void __iar_system_Mtxinit (__iar_Rmtx * mutex ) /* Initialize a system lock */
200
+ {
201
+ osMutexDef_t def ;
202
+ uint32_t index ;
203
+ for (index = 0 ; index < _MAX_LOCK ; index ++ ) {
204
+ if (0 == std_mutex_id_sys [index ]) {
205
+ def .mutex = & std_mutex_sys [index ];
206
+ std_mutex_id_sys [index ] = osMutexCreate (& def );
207
+ * mutex = (__iar_Rmtx * )& std_mutex_id_sys [index ];
208
+ return ;
209
+ }
210
+ }
211
+ // This should never happen
212
+ error ("Not enough mutexes\n" );
213
+ }
214
+
215
+ void __iar_system_Mtxdst (__iar_Rmtx * mutex )/*Destroy a system lock */
216
+ {
217
+ osMutexDelete (* (osMutexId * )* mutex );
218
+ * mutex = 0 ;
219
+ }
220
+
221
+ void __iar_system_Mtxlock (__iar_Rmtx * mutex ) /* Lock a system lock */
222
+ {
223
+ osMutexWait (* (osMutexId * )* mutex , osWaitForever );
224
+ }
225
+
226
+ void __iar_system_Mtxunlock (__iar_Rmtx * mutex ) /* Unlock a system lock */
227
+ {
228
+ osMutexRelease (* (osMutexId * )* mutex );
229
+ }
230
+
231
+ void __iar_file_Mtxinit (__iar_Rmtx * mutex )/*Initialize a file lock */
232
+ {
233
+ osMutexDef_t def ;
234
+ uint32_t index ;
235
+ for (index = 0 ; index < _FOPEN_MAX ; index ++ ) {
236
+ if (0 == std_mutex_id_file [index ]) {
237
+ def .mutex = & std_mutex_file [index ];
238
+ std_mutex_id_file [index ] = osMutexCreate (& def );
239
+ * mutex = (__iar_Rmtx * )& std_mutex_id_file [index ];
240
+ return ;
241
+ }
242
+ }
243
+ // The variable _FOPEN_MAX needs to be increased
244
+ error ("Not enough mutexes\n" );
245
+ }
246
+
247
+ void __iar_file_Mtxdst (__iar_Rmtx * mutex ) /* Destroy a file lock */
248
+ {
249
+ osMutexDelete (* (osMutexId * )* mutex );
250
+ * mutex = 0 ;
251
+ }
252
+
253
+ void __iar_file_Mtxlock (__iar_Rmtx * mutex ) /* Lock a file lock */
254
+ {
255
+ osMutexWait (* (osMutexId * )* mutex , osWaitForever );
256
+ }
257
+
258
+ void __iar_file_Mtxunlock (__iar_Rmtx * mutex ) /* Unlock a file lock */
259
+ {
260
+ osMutexRelease (* (osMutexId * )* mutex );
261
+ }
262
+
263
+ #endif
193
264
194
265
/*----------------------------------------------------------------------------
195
266
* RTX Optimizations (empty functions)
@@ -553,20 +624,25 @@ __asm void __rt_entry (void) {
553
624
554
625
#elif defined (__GNUC__ )
555
626
627
+ osMutexDef (malloc_mutex );
628
+ static osMutexId malloc_mutex_id ;
629
+ osMutexDef (env_mutex );
630
+ static osMutexId env_mutex_id ;
631
+
556
632
extern void __libc_fini_array (void );
557
633
extern void __libc_init_array (void );
558
634
extern int main (int argc , char * * argv );
559
635
560
636
void pre_main (void ) {
637
+ malloc_mutex_id = osMutexCreate (osMutex (malloc_mutex ));
638
+ env_mutex_id = osMutexCreate (osMutex (env_mutex ));
561
639
atexit (__libc_fini_array );
562
640
__libc_init_array ();
563
641
main (0 , NULL );
564
642
}
565
643
566
644
__attribute__((naked )) void software_init_hook (void ) {
567
645
__asm (
568
- ".syntax unified\n"
569
- ".thumb\n"
570
646
"bl osKernelInitialize\n"
571
647
#ifdef __MBED_CMSIS_RTOS_CM
572
648
"bl set_main_stack\n"
@@ -580,6 +656,29 @@ __attribute__((naked)) void software_init_hook (void) {
580
656
);
581
657
}
582
658
659
+ // Opaque declaration of _reent structure
660
+ struct _reent ;
661
+
662
+ void __malloc_lock ( struct _reent * _r )
663
+ {
664
+ osMutexWait (malloc_mutex_id , osWaitForever );
665
+ }
666
+
667
+ void __malloc_unlock ( struct _reent * _r )
668
+ {
669
+ osMutexRelease (malloc_mutex_id );
670
+ }
671
+
672
+ void __env_lock ( struct _reent * _r )
673
+ {
674
+ osMutexWait (env_mutex_id , osWaitForever );
675
+ }
676
+
677
+ void __env_unlock ( struct _reent * _r )
678
+ {
679
+ osMutexRelease (env_mutex_id );
680
+ }
681
+
583
682
#elif defined (__ICCARM__)
584
683
585
684
extern void * __vector_table ;
0 commit comments