Skip to content

Commit 4a4ab8b

Browse files
TomoYamanakaadbridge
authored andcommitted
Support RTX v4.80 for Cortex-A and a few Malloc API
PR to update RTX to v4.80 for Cortex-A. In the latest CI test, three tests result in an error. The cause is mainly three points - Unsupport RTX v4.80 for Cortex-A - Insufficient stack size of thread defined in test - A few Lack of Malloc API in GCC Therefore, I supported to these. For the stack size for test, @russ already supported in PR #3362. Reference for issue of test error is here. #3273 Reference for PR to update RTX for Cortex-M. #1702
1 parent 2885c1b commit 4a4ab8b

38 files changed

+1350
-1410
lines changed

rtos/RtosTimer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ class RtosTimer {
144144
mbed::Callback<void()> _function;
145145
osTimerId _timer_id;
146146
osTimerDef_t _timer;
147-
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
148-
uint32_t _timer_data[5];
149-
#else
147+
#ifdef CMSIS_OS_RTX
150148
uint32_t _timer_data[6];
151149
#endif
152150
};

rtos/rtx/TARGET_CORTEX_A/HAL_CA.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*----------------------------------------------------------------------------
2-
* RL-ARM - RTX
2+
* CMSIS-RTOS - RTX
33
*----------------------------------------------------------------------------
44
* Name: HAL_CA.C
55
* Purpose: Hardware Abstraction Layer for Cortex-A
6-
* Rev.:
6+
* Rev.: V4.77 plus changes for RTX-Ax
77
*----------------------------------------------------------------------------
88
*
9-
* Copyright (c) 2012 ARM Limited
9+
* Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH, 2012-2015 ARM Limited
1010
* All rights reserved.
1111
* Redistribution and use in source and binary forms, with or without
1212
* modification, are permitted provided that the following conditions are met:
@@ -15,19 +15,19 @@
1515
* - Redistributions in binary form must reproduce the above copyright
1616
* notice, this list of conditions and the following disclaimer in the
1717
* 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
2020
* specific prior written permission.
2121
*
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
2424
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2525
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
2626
* 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)
3131
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
* POSSIBILITY OF SUCH DAMAGE.
3333
*---------------------------------------------------------------------------*/
@@ -44,14 +44,14 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
4444

4545
/* Prepare a complete interrupt frame for first task start */
4646
size = p_TCB->priv_stack >> 2;
47-
if (size == 0) {
47+
if (size == 0U) {
4848
size = (U16)os_stackinfo >> 2;
4949
}
5050
/* Write to the top of stack. */
5151
stk = &p_TCB->stack[size];
5252

5353
/* Auto correct to 8-byte ARM stack alignment. */
54-
if ((U32)stk & 0x04) {
54+
if ((U32)stk & 0x04U) {
5555
stk--;
5656
}
5757

@@ -69,10 +69,10 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
6969
/* Assign a void pointer to R0. */
7070
stk[8] = (U32)p_TCB->msg;
7171
/* Clear R1-R12,LR registers. */
72-
for (i = 0; i < 8; i++) {
73-
stk[i] = 0;
72+
for (i = 0U; i < 8U; i++) {
73+
stk[i] = 0U;
7474
}
75-
for (i = 9; i < 14; i++) {
75+
for (i = 9U; i < 14U; i++) {
7676
stk[i] = 0;
7777
}
7878

@@ -82,6 +82,20 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
8282
/* Task entry point. */
8383
p_TCB->ptask = task_body;
8484

85+
/* Initialize stack with magic pattern. */
86+
if (os_stackinfo & 0x10000000U) {
87+
if (size > (16U+1U)) {
88+
for (i = ((size - 16U)/2U) - 1U; i; i--) {
89+
stk -= 2U;
90+
stk[1] = MAGIC_PATTERN;
91+
stk[0] = MAGIC_PATTERN;
92+
}
93+
if (--stk > p_TCB->stack) {
94+
*stk = MAGIC_PATTERN;
95+
}
96+
}
97+
}
98+
8599
/* Set a magic word for checking of stack overflow. */
86100
p_TCB->stack[0] = MAGIC_WORD;
87101
}
@@ -93,13 +107,13 @@ static __inline U32 *rt_ret_regs (P_TCB p_TCB) {
93107
/* Get pointer to task return value registers (R0..R3) in Stack */
94108
if (p_TCB->stack_frame & 0x4) {
95109
/* NEON/D32 Stack Frame: D0-31,FPSCR,Reserved,R4-R11,R0-R3,R12,LR,PC,xPSR */
96-
return (U32 *)(p_TCB->tsk_stack + 8*4 + 2*4 + 32*8);
110+
return (U32 *)(p_TCB->tsk_stack + (8U*4U) + (2U*4U) + (32U*8U));
97111
} else if (p_TCB->stack_frame & 0x2) {
98112
/* VFP/D16 Stack Frame: D0-D15/S0-31,FPSCR,Reserved,R4-R11,R0-R3,R12,LR,PC,xPSR */
99-
return (U32 *)(p_TCB->tsk_stack + 8*4 + 2*4 + 32*4);
113+
return (U32 *)(p_TCB->tsk_stack + (8U*4U) + (2U*4U) + (32U*4U));
100114
} else {
101115
/* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
102-
return (U32 *)(p_TCB->tsk_stack + 8*4);
116+
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
103117
}
104118
}
105119

rtos/rtx/TARGET_CORTEX_A/RTX_CM_lib.h

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*----------------------------------------------------------------------------
2-
* RL-ARM - RTX
2+
* CMSIS-RTOS - RTX
33
*----------------------------------------------------------------------------
44
* Name: RTX_CM_LIB.H
55
* Purpose: RTX Kernel System Configuration
6-
* Rev.: V4.73
6+
* Rev.: V4.79
77
*----------------------------------------------------------------------------
88
*
9-
* Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
9+
* Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
1010
* All rights reserved.
1111
* Redistribution and use in source and binary forms, with or without
1212
* modification, are permitted provided that the following conditions are met:
@@ -15,19 +15,19 @@
1515
* - Redistributions in binary form must reproduce the above copyright
1616
* notice, this list of conditions and the following disclaimer in the
1717
* 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
2020
* specific prior written permission.
2121
*
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
2424
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2525
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
2626
* 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)
3131
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
* POSSIBILITY OF SUCH DAMAGE.
3333
*---------------------------------------------------------------------------*/
@@ -63,9 +63,10 @@ typedef uint32_t OS_RESULT;
6363

6464
#define runtask_id() rt_tsk_self()
6565
#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)
6767
#define mutex_rel(m) os_mut_release(m)
6868

69+
extern uint8_t os_running;
6970
extern OS_TID rt_tsk_self (void);
7071
extern void rt_mut_init (OS_ID mutex);
7172
extern OS_RESULT rt_mut_release (OS_ID mutex);
@@ -140,6 +141,14 @@ void __iar_system_Mtxunlock(__iar_Rmtx *);
140141
* Global Variables
141142
*---------------------------------------------------------------------------*/
142143

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+
143152
#if (OS_TIMERS != 0)
144153
#define OS_TASK_CNT (OS_TASKCNT + 1)
145154
#ifndef __MBED_CMSIS_RTOS_CA9
@@ -154,24 +163,32 @@ void __iar_system_Mtxunlock(__iar_Rmtx *);
154163
#endif
155164
#endif
156165

166+
#ifndef OS_STKINIT
167+
#define OS_STKINIT 0
168+
#endif
169+
157170
uint16_t const os_maxtaskrun = OS_TASK_CNT;
158171
#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);
160173
#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);
162175
#endif
163176
uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
164177
uint32_t const os_tickfreq = OS_CLOCK;
165178
uint16_t const os_tickus_i = OS_CLOCK/1000000;
166179
uint16_t const os_tickus_f = (((uint64_t)(OS_CLOCK-1000000*(OS_CLOCK/1000000)))<<16)/1000000;
167180
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) */
168184
uint8_t const os_flags = OS_RUNPRIV;
185+
#endif /* defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) */
169186

170187
/* Export following defines to uVision debugger. */
171188
__USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS;
172189
__USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX;
173190
__USED uint32_t const os_clockrate = OS_TICK;
174-
__USED uint32_t const os_timernum = 0;
191+
__USED uint32_t const os_timernum = 0U;
175192

176193
/* Memory pool for TCB allocation */
177194
_declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT);
@@ -216,14 +233,14 @@ osMessageQId osMessageQId_osTimerMessageQ;
216233
#else
217234
osThreadDef_t os_thread_def_osTimerThread = { NULL };
218235
osThreadId osThreadId_osTimerThread;
219-
osMessageQDef(osTimerMessageQ, 0, void *);
236+
osMessageQDef(osTimerMessageQ, 0U, void *);
220237
osMessageQId osMessageQId_osTimerMessageQ;
221238
#endif
222239

223240
/* Legacy RTX User Timers not used */
224-
uint32_t os_tmr = 0;
241+
uint32_t os_tmr = 0U;
225242
uint32_t const *m_tmr = NULL;
226-
uint16_t const mp_tmr_size = 0;
243+
uint16_t const mp_tmr_size = 0U;
227244

228245
/* singleton mutex */
229246
osMutexId singleton_mutex_id;
@@ -272,8 +289,8 @@ void *__user_perthread_libspace (void) {
272289
/* Provide a separate libspace for each task. */
273290
uint32_t idx;
274291

275-
idx = runtask_id ();
276-
if (idx == 0) {
292+
idx = (os_running != 0U) ? runtask_id () : 0U;
293+
if (idx == 0U) {
277294
/* RTX not running yet. */
278295
return (&__libspace_start);
279296
}
@@ -299,7 +316,7 @@ int _mutex_initialize (OS_ID *mutex) {
299316

300317
__attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
301318
/* Acquire a system mutex, lock stdlib resources. */
302-
if (runtask_id ()) {
319+
if (os_running) {
303320
/* RTX running, acquire a mutex. */
304321
mutex_wait (*mutex);
305322
}
@@ -310,7 +327,7 @@ __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
310327

311328
__attribute__((used)) void _mutex_release (OS_ID *mutex) {
312329
/* Release a system mutex, unlock stdlib resources. */
313-
if (runtask_id ()) {
330+
if (os_running) {
314331
/* RTX running, release a mutex. */
315332
mutex_rel (*mutex);
316333
}
@@ -403,9 +420,9 @@ void __iar_system_Mtxunlock(__iar_Rmtx *mutex)
403420
extern void pre_main (void);
404421
#ifdef __MBED_CMSIS_RTOS_CA9
405422
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 };
407424
#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 };
409426
#endif
410427

411428
#if defined (__CC_ARM)
@@ -485,14 +502,21 @@ __asm void __rt_entry (void) {
485502
#endif
486503

487504
#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+
488511
extern int atexit(void (*func)(void));
489512
extern void __libc_fini_array(void);
490513
extern void __libc_init_array (void);
491514
extern int main(int argc, char **argv);
492515

493516
void pre_main(void) {
494517
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));
496520
__libc_init_array();
497521
main(0, NULL);
498522
}
@@ -511,6 +535,29 @@ __attribute__((naked)) void software_init_hook_rtos (void) {
511535
);
512536
}
513537

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+
514561
#elif defined (__ICCARM__)
515562
extern void* __vector_core_a9;
516563
extern int __low_level_init(void);
@@ -533,7 +580,7 @@ void pre_main(void) {
533580
}
534581

535582
#pragma required=__vector_core_a9
536-
void __iar_program_start( void )
583+
void __iar_program_start(void)
537584
{
538585
__iar_init_core();
539586
__iar_init_vfp();
@@ -556,8 +603,6 @@ void __iar_program_start( void )
556603

557604
#endif
558605

559-
560606
/*----------------------------------------------------------------------------
561607
* end of file
562608
*---------------------------------------------------------------------------*/
563-

0 commit comments

Comments
 (0)