1
1
/*----------------------------------------------------------------------------
2
- * RL-ARM - RTX
2
+ * CMSIS-RTOS - RTX
3
3
*----------------------------------------------------------------------------
4
4
* Name: HAL_CM.C
5
5
* Purpose: Hardware Abstraction Layer for Cortex-M
6
- * Rev.: V4.60
6
+ * Rev.: V4.79
7
7
*----------------------------------------------------------------------------
8
8
*
9
- * Copyright (c) 1999-2009 KEIL, 2009-2012 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:
33
33
*---------------------------------------------------------------------------*/
34
34
35
35
#include "rt_TypeDef.h"
36
- #include "RTX_Conf .h"
36
+ #include "RTX_Config .h"
37
37
#include "rt_HAL_CM.h"
38
38
39
39
@@ -58,12 +58,15 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
58
58
59
59
/* Prepare a complete interrupt frame for first task start */
60
60
size = p_TCB -> priv_stack >> 2 ;
61
+ if (size == 0U ) {
62
+ size = (U16 )os_stackinfo >> 2 ;
63
+ }
61
64
62
65
/* Write to the top of stack. */
63
66
stk = & p_TCB -> stack [size ];
64
67
65
68
/* Auto correct to 8-byte ARM stack alignment. */
66
- if ((U32 )stk & 0x04 ) {
69
+ if ((U32 )stk & 0x04U ) {
67
70
stk -- ;
68
71
}
69
72
@@ -74,8 +77,8 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
74
77
stk [14 ] = (U32 )task_body ;
75
78
76
79
/* 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 ;
79
82
}
80
83
81
84
/* Assign a void pointer to R0. */
@@ -87,31 +90,50 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
87
90
/* Task entry point. */
88
91
p_TCB -> ptask = task_body ;
89
92
93
+ /* Initialize stack with magic pattern. */
94
+ if (os_stackinfo & 0x10000000U ) {
95
+ if (size > (16U + 1U )) {
96
+ for (i = ((size - 16U )/2U ) - 1U ; i ; i -- ) {
97
+ stk -= 2U ;
98
+ stk [1 ] = MAGIC_PATTERN ;
99
+ stk [0 ] = MAGIC_PATTERN ;
100
+ }
101
+ if (-- stk > p_TCB -> stack ) {
102
+ * stk = MAGIC_PATTERN ;
103
+ }
104
+ }
105
+ }
106
+
107
+ #ifdef __MBED_CMSIS_RTOS_CM
90
108
/* 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
109
+ For the main thread (ID: 0x02 ) the stack is in a memory area shared with the
92
110
heap, therefore the last word of the stack is a moving target.
93
111
We want to do stack/heap collision detection instead.
94
112
*/
95
- if (p_TCB -> task_id != 0x01 )
113
+ if (p_TCB -> task_id != 0x02 )
96
114
p_TCB -> stack [0 ] = MAGIC_WORD ;
115
+ #else
116
+ /* Set a magic word for checking of stack overflow. */
117
+ p_TCB -> stack [0 ] = MAGIC_WORD ;
118
+ #endif
97
119
}
98
120
99
121
100
122
/*--------------------------- rt_ret_val ----------------------------------*/
101
123
102
124
static __inline U32 * rt_ret_regs (P_TCB p_TCB ) {
103
125
/* Get pointer to task return value registers (R0..R3) in Stack */
104
- #if (__TARGET_FPU_VFP )
126
+ #if defined (__TARGET_FPU_VFP )
105
127
if (p_TCB -> stack_frame ) {
106
128
/* 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 );
129
+ return (U32 * )(p_TCB -> tsk_stack + ( 8U * 4U ) + ( 16U * 4U ) );
108
130
} else {
109
131
/* Basic Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
110
- return (U32 * )(p_TCB -> tsk_stack + 8 * 4 );
132
+ return (U32 * )(p_TCB -> tsk_stack + ( 8U * 4U ) );
111
133
}
112
134
#else
113
135
/* Stack Frame: R4-R11,R0-R3,R12,LR,PC,xPSR */
114
- return (U32 * )(p_TCB -> tsk_stack + 8 * 4 );
136
+ return (U32 * )(p_TCB -> tsk_stack + ( 8U * 4U ) );
115
137
#endif
116
138
}
117
139
@@ -135,9 +157,9 @@ void rt_ret_val2(P_TCB p_TCB, U32 v0, U32 v1) {
135
157
136
158
#ifdef DBG_MSG
137
159
void dbg_init (void ) {
138
- if ((DEMCR & DEMCR_TRCENA ) &&
139
- (ITM_CONTROL & ITM_ITMENA ) &&
140
- (ITM_ENABLE & (1UL << 31 ))) {
160
+ if ((( DEMCR & DEMCR_TRCENA ) != 0U ) &&
161
+ (( ITM_CONTROL & ITM_ITMENA ) != 0U ) &&
162
+ (( ITM_ENABLE & (1UL << 31 )) != 0U )) {
141
163
dbg_msg = __TRUE ;
142
164
}
143
165
}
@@ -147,24 +169,22 @@ void dbg_init (void) {
147
169
148
170
#ifdef DBG_MSG
149
171
void dbg_task_notify (P_TCB p_tcb , BOOL create ) {
150
- while (ITM_PORT31_U32 == 0 );
172
+ while (ITM_PORT31_U32 == 0U );
151
173
ITM_PORT31_U32 = (U32 )p_tcb -> ptask ;
152
- while (ITM_PORT31_U32 == 0 );
153
- ITM_PORT31_U16 = (create << 8 ) | p_tcb -> task_id ;
174
+ while (ITM_PORT31_U32 == 0U );
175
+ ITM_PORT31_U16 = (U16 )(( create << 8 ) | p_tcb -> task_id ) ;
154
176
}
155
177
#endif
156
178
157
179
/*--------------------------- dbg_task_switch -------------------------------*/
158
180
159
181
#ifdef DBG_MSG
160
182
void dbg_task_switch (U32 task_id ) {
161
- while (ITM_PORT31_U32 == 0 );
162
- ITM_PORT31_U8 = task_id ;
183
+ while (ITM_PORT31_U32 == 0U );
184
+ ITM_PORT31_U8 = ( U8 ) task_id ;
163
185
}
164
186
#endif
165
187
166
-
167
188
/*----------------------------------------------------------------------------
168
189
* end of file
169
190
*---------------------------------------------------------------------------*/
170
-
0 commit comments