Skip to content

Commit 860fdd2

Browse files
committed
Merge pull request #1702 from 0xc0170/dev_rtos_update
rtx update to v4.79
2 parents fcf2974 + cacf085 commit 860fdd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2361
-1283
lines changed

libraries/net/lwip/lwip-sys/arch/sys_arch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void sys_sem_free(sys_sem_t *sem) {}
285285
* @return a new mutex */
286286
err_t sys_mutex_new(sys_mutex_t *mutex) {
287287
#ifdef CMSIS_OS_RTX
288-
#ifdef __MBED_CMSIS_RTOS_CA9
288+
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
289289
memset(mutex->data, 0, sizeof(int32_t)*4);
290290
#else
291291
memset(mutex->data, 0, sizeof(int32_t)*3);

libraries/net/lwip/lwip-sys/arch/sys_arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ typedef struct {
4040
osMutexId id;
4141
osMutexDef_t def;
4242
#ifdef CMSIS_OS_RTX
43-
#ifdef __MBED_CMSIS_RTOS_CA9
43+
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
4444
int32_t data[4];
4545
#else
4646
int32_t data[3];

libraries/rtos/rtos/Mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Mutex {
5757
osMutexId _osMutexId;
5858
osMutexDef_t _osMutexDef;
5959
#ifdef CMSIS_OS_RTX
60-
#ifdef __MBED_CMSIS_RTOS_CA9
60+
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
6161
int32_t _mutex_data[4];
6262
#else
6363
int32_t _mutex_data[3];

libraries/rtos/rtos/RtosTimer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ class RtosTimer {
6161
private:
6262
osTimerId _timer_id;
6363
osTimerDef_t _timer;
64-
#ifdef CMSIS_OS_RTX
64+
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
6565
uint32_t _timer_data[5];
66+
#else
67+
uint32_t _timer_data[6];
6668
#endif
6769
};
6870

libraries/rtos/rtos/Thread.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
#include "mbed_error.h"
2525
#include "rtos_idle.h"
2626

27+
// rt_tid2ptcb is an internal function which we exposed to get TCB for thread id
28+
#undef NULL //Workaround for conflicting macros in rt_TypeDef.h and stdio.h
29+
#include "rt_TypeDef.h"
30+
31+
extern "C" P_TCB rt_tid2ptcb(osThreadId thread_id);
32+
2733
namespace rtos {
2834

2935
Thread::Thread(void (*task)(void const *argument), void *argument,
3036
osPriority priority, uint32_t stack_size, unsigned char *stack_pointer) {
31-
#ifdef CMSIS_OS_RTX
37+
#ifdef __MBED_CMSIS_RTOS_CM
3238
_thread_def.pthread = task;
3339
_thread_def.tpriority = priority;
3440
_thread_def.stacksize = stack_size;
@@ -71,8 +77,10 @@ int32_t Thread::signal_clr(int32_t signals) {
7177
}
7278

7379
Thread::State Thread::get_state() {
74-
#ifndef __MBED_CMSIS_RTOS_CA9
80+
#if !defined(__MBED_CMSIS_RTOS_CA9) && !defined(__MBED_CMSIS_RTOS_CM)
81+
#ifdef CMSIS_OS_RTX
7582
return ((State)_thread_def.tcb.state);
83+
#endif
7684
#else
7785
uint8_t status;
7886
status = osThreadGetState(_tid);
@@ -82,36 +90,61 @@ Thread::State Thread::get_state() {
8290

8391
uint32_t Thread::stack_size() {
8492
#ifndef __MBED_CMSIS_RTOS_CA9
93+
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
8594
return _thread_def.tcb.priv_stack;
95+
#else
96+
P_TCB tcb = rt_tid2ptcb(_tid);
97+
return tcb->priv_stack;
98+
#endif
8699
#else
87100
return 0;
88101
#endif
89102
}
90103

91104
uint32_t Thread::free_stack() {
92105
#ifndef __MBED_CMSIS_RTOS_CA9
106+
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
93107
uint32_t bottom = (uint32_t)_thread_def.tcb.stack;
94108
return _thread_def.tcb.tsk_stack - bottom;
109+
#else
110+
P_TCB tcb = rt_tid2ptcb(_tid);
111+
uint32_t bottom = (uint32_t)tcb->stack;
112+
return tcb->tsk_stack - bottom;
113+
#endif
95114
#else
96115
return 0;
97116
#endif
98117
}
99118

100119
uint32_t Thread::used_stack() {
101120
#ifndef __MBED_CMSIS_RTOS_CA9
121+
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
102122
uint32_t top = (uint32_t)_thread_def.tcb.stack + _thread_def.tcb.priv_stack;
103123
return top - _thread_def.tcb.tsk_stack;
124+
#else
125+
P_TCB tcb = rt_tid2ptcb(_tid);
126+
uint32_t top = (uint32_t)tcb->stack + tcb->priv_stack;
127+
return top - tcb->tsk_stack;
128+
#endif
104129
#else
105130
return 0;
106131
#endif
107132
}
108133

109134
uint32_t Thread::max_stack() {
110135
#ifndef __MBED_CMSIS_RTOS_CA9
136+
#if defined(CMSIS_OS_RTX) && !defined(__MBED_CMSIS_RTOS_CM)
111137
uint32_t high_mark = 0;
112138
while (_thread_def.tcb.stack[high_mark] == 0xE25A2EA5)
113139
high_mark++;
114140
return _thread_def.tcb.priv_stack - (high_mark * 4);
141+
#else
142+
P_TCB tcb = rt_tid2ptcb(_tid);
143+
uint32_t high_mark = 0;
144+
while (tcb->stack[high_mark] == 0xE25A2EA5)
145+
high_mark++;
146+
return tcb->priv_stack - (high_mark * 4);
147+
#endif
115148
#else
116149
return 0;
117150
#endif
@@ -139,9 +172,11 @@ void Thread::attach_idle_hook(void (*fptr)(void)) {
139172

140173
Thread::~Thread() {
141174
terminate();
175+
#ifdef __MBED_CMSIS_RTOS_CM
142176
if (_dynamic_stack) {
143177
delete[] (_thread_def.stack_pointer);
144178
}
179+
#endif
145180
}
146181

147182
}

libraries/rtos/rtx/TARGET_CORTEX_M/HAL_CM.c

Lines changed: 61 additions & 24 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_CM.C
55
* Purpose: Hardware Abstraction Layer for Cortex-M
6-
* Rev.: V4.60
6+
* Rev.: V4.79
77
*----------------------------------------------------------------------------
88
*
9-
* Copyright (c) 1999-2009 KEIL, 2009-2012 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:
@@ -33,7 +33,7 @@
3333
*---------------------------------------------------------------------------*/
3434

3535
#include "rt_TypeDef.h"
36-
#include "RTX_Conf.h"
36+
#include "RTX_Config.h"
3737
#include "rt_HAL_CM.h"
3838

3939

@@ -58,12 +58,15 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
5858

5959
/* Prepare a complete interrupt frame for first task start */
6060
size = p_TCB->priv_stack >> 2;
61+
if (size == 0U) {
62+
size = (U16)os_stackinfo >> 2;
63+
}
6164

6265
/* Write to the top of stack. */
6366
stk = &p_TCB->stack[size];
6467

6568
/* Auto correct to 8-byte ARM stack alignment. */
66-
if ((U32)stk & 0x04) {
69+
if ((U32)stk & 0x04U) {
6770
stk--;
6871
}
6972

@@ -74,8 +77,8 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
7477
stk[14] = (U32)task_body;
7578

7679
/* Clear R4-R11,R0-R3,R12,LR registers. */
77-
for (i = 0; i < 14; i++) {
78-
stk[i] = 0;
80+
for (i = 0U; i < 14U; i++) {
81+
stk[i] = 0U;
7982
}
8083

8184
/* Assign a void pointer to R0. */
@@ -87,31 +90,67 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
8790
/* Task entry point. */
8891
p_TCB->ptask = task_body;
8992

93+
94+
#ifdef __MBED_CMSIS_RTOS_CM
9095
/* Set a magic word for checking of stack overflow.
91-
For the main thread (ID: 0x01) the stack is in a memory area shared with the
96+
For the main thread (ID: 0x02) the stack is in a memory area shared with the
9297
heap, therefore the last word of the stack is a moving target.
9398
We want to do stack/heap collision detection instead.
99+
Similar applies to stack filling for the magic pattern.
94100
*/
95-
if (p_TCB->task_id != 0x01)
96-
p_TCB->stack[0] = MAGIC_WORD;
101+
if (p_TCB->task_id != 0x02) {
102+
p_TCB->stack[0] = MAGIC_WORD;
103+
104+
/* Initialize stack with magic pattern. */
105+
if (os_stackinfo & 0x10000000U) {
106+
if (size > (16U+1U)) {
107+
for (i = ((size - 16U)/2U) - 1U; i; i--) {
108+
stk -= 2U;
109+
stk[1] = MAGIC_PATTERN;
110+
stk[0] = MAGIC_PATTERN;
111+
}
112+
if (--stk > p_TCB->stack) {
113+
*stk = MAGIC_PATTERN;
114+
}
115+
}
116+
}
117+
}
118+
#else
119+
/* Initialize stack with magic pattern. */
120+
if (os_stackinfo & 0x10000000U) {
121+
if (size > (16U+1U)) {
122+
for (i = ((size - 16U)/2U) - 1U; i; i--) {
123+
stk -= 2U;
124+
stk[1] = MAGIC_PATTERN;
125+
stk[0] = MAGIC_PATTERN;
126+
}
127+
if (--stk > p_TCB->stack) {
128+
*stk = MAGIC_PATTERN;
129+
}
130+
}
131+
}
132+
133+
/* Set a magic word for checking of stack overflow. */
134+
p_TCB->stack[0] = MAGIC_WORD;
135+
#endif
97136
}
98137

99138

100139
/*--------------------------- rt_ret_val ----------------------------------*/
101140

102141
static __inline U32 *rt_ret_regs (P_TCB p_TCB) {
103142
/* Get pointer to task return value registers (R0..R3) in Stack */
104-
#if (__TARGET_FPU_VFP)
143+
#if defined(__TARGET_FPU_VFP)
105144
if (p_TCB->stack_frame) {
106145
/* Extended Stack Frame: R4-R11,S16-S31,R0-R3,R12,LR,PC,xPSR,S0-S15,FPSCR */
107-
return (U32 *)(p_TCB->tsk_stack + 8*4 + 16*4);
146+
return (U32 *)(p_TCB->tsk_stack + (8U*4U) + (16U*4U));
108147
} else {
109148
/* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
110-
return (U32 *)(p_TCB->tsk_stack + 8*4);
149+
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
111150
}
112151
#else
113152
/* Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
114-
return (U32 *)(p_TCB->tsk_stack + 8*4);
153+
return (U32 *)(p_TCB->tsk_stack + (8U*4U));
115154
#endif
116155
}
117156

@@ -135,9 +174,9 @@ void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) {
135174

136175
#ifdef DBG_MSG
137176
void dbg_init (void) {
138-
if ((DEMCR & DEMCR_TRCENA) &&
139-
(ITM_CONTROL & ITM_ITMENA) &&
140-
(ITM_ENABLE & (1UL << 31))) {
177+
if (((DEMCR & DEMCR_TRCENA) != 0U) &&
178+
((ITM_CONTROL & ITM_ITMENA) != 0U) &&
179+
((ITM_ENABLE & (1UL << 31)) != 0U)) {
141180
dbg_msg = __TRUE;
142181
}
143182
}
@@ -147,24 +186,22 @@ void dbg_init (void) {
147186

148187
#ifdef DBG_MSG
149188
void dbg_task_notify (P_TCB p_tcb, BOOL create) {
150-
while (ITM_PORT31_U32 == 0);
189+
while (ITM_PORT31_U32 == 0U);
151190
ITM_PORT31_U32 = (U32)p_tcb->ptask;
152-
while (ITM_PORT31_U32 == 0);
153-
ITM_PORT31_U16 = (create << 8) | p_tcb->task_id;
191+
while (ITM_PORT31_U32 == 0U);
192+
ITM_PORT31_U16 = (U16)((create << 8) | p_tcb->task_id);
154193
}
155194
#endif
156195

157196
/*--------------------------- dbg_task_switch -------------------------------*/
158197

159198
#ifdef DBG_MSG
160199
void dbg_task_switch (U32 task_id) {
161-
while (ITM_PORT31_U32 == 0);
162-
ITM_PORT31_U8 = task_id;
200+
while (ITM_PORT31_U32 == 0U);
201+
ITM_PORT31_U8 = (U8)task_id;
163202
}
164203
#endif
165204

166-
167205
/*----------------------------------------------------------------------------
168206
* end of file
169207
*---------------------------------------------------------------------------*/
170-

0 commit comments

Comments
 (0)