Skip to content

Commit d9d2e73

Browse files
committed
- ARM standard C library interface updated
- EvrFreeRTOSSetup: reset option added
1 parent 2b794ed commit d9d2e73

8 files changed

Lines changed: 131 additions & 35 deletions

File tree

ARM.CMSIS-FreeRTOS.pdsc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<license>License/license.txt</license>
99

1010
<releases>
11+
<release version="10.0.2-dev4">
12+
CMSIS:RTOS2:FreeRTOS update:
13+
- Updated ARM standard C library interface
14+
</release>
1115
<release version="10.0.2-dev3">
1216
CMSIS:RTOS2:FreeRTOS update:
1317
- Added Event Recorder configuration

CMSIS/RTOS2/FreeRTOS/Examples/Native_Blinky/Blinky.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void app_main (void *argument) {
132132
int main (void) {
133133
SystemCoreClockUpdate();
134134

135-
EvrFreeRTOSSetup();
135+
EvrFreeRTOSSetup(0);
136136

137137
xTaskCreate (app_main, "app_main", 64, NULL, tskIDLE_PRIORITY+1, NULL);
138138

CMSIS/RTOS2/FreeRTOS/Include/freertos_evr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545

4646
/**
4747
\brief Setup Event Recorder configuration
48+
\param[in] reset reset if already configured (0:no reset, 1:reset)
4849
*/
49-
extern void EvrFreeRTOSSetup (void);
50+
extern void EvrFreeRTOSSetup (uint32_t reset);
5051

5152
/**
5253
\brief Event on successful task create (Op)

CMSIS/RTOS2/FreeRTOS/Source/ARM/clib_arm.c

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* --------------------------------------------------------------------------
2-
* Copyright (c) 2013-2017 Arm Limited. All rights reserved.
2+
* Copyright (c) 2013-2019 Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -23,32 +23,40 @@
2323
#include <stdint.h>
2424
#include <stddef.h>
2525

26-
#include "cmsis_os2.h"
27-
#include "cmsis_compiler.h"
26+
#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
27+
#include "task.h" // ARM.FreeRTOS::RTOS:Core
28+
#include "semphr.h" // ARM.FreeRTOS::RTOS:Core
2829

2930
/* Define the number of Threads which use standard C/C++ library libspace */
3031
#ifndef OS_THREAD_LIBSPACE_NUM
3132
#define OS_THREAD_LIBSPACE_NUM 4
3233
#endif
3334

35+
/* Define the number of Mutexes used by standard C/C++ library for stream protection */
36+
#ifndef OS_MUTEX_CLIB_NUM
37+
#define OS_MUTEX_CLIB_NUM 5
38+
#endif
39+
3440
/*----------------------------------------------------------------------------*/
3541

36-
/* Initialize OS */
42+
/* Initialization after stack and heap setup */
3743
#if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
3844

3945
#ifndef __MICROLIB
4046
__WEAK
4147
void _platform_post_stackheap_init (void);
4248
void _platform_post_stackheap_init (void) {
43-
osKernelInitialize();
49+
/* Initialize OS, memory, etc. */
50+
EvrFreeRTOSSetup(0);
4451
}
4552
#endif /* __MICROLIB */
4653

4754
#elif defined(__GNUC__)
4855
__WEAK
4956
void software_init_hook (void);
5057
void software_init_hook (void) {
51-
osKernelInitialize();
58+
/* Initialize OS, memory, etc. */
59+
EvrFreeRTOSSetup(0);
5260
}
5361

5462
#endif
@@ -64,14 +72,14 @@ void software_init_hook (void) {
6472
static uint32_t os_libspace[OS_THREAD_LIBSPACE_NUM+1][LIBSPACE_SIZE/sizeof(uint32_t)];
6573

6674
/* Array of Threads (IDs) using libspace */
67-
static osThreadId_t os_libspace_id[OS_THREAD_LIBSPACE_NUM];
75+
static TaskHandle_t os_libspace_id[OS_THREAD_LIBSPACE_NUM];
6876

6977
/* OS Kernel state checking */
7078
static uint32_t os_kernel_is_active (void) {
7179
static uint8_t os_kernel_active = 0U;
7280

7381
if (os_kernel_active == 0U) {
74-
if (osKernelGetState() > osKernelReady) {
82+
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
7583
os_kernel_active = 1U;
7684
return 1U;
7785
}
@@ -82,18 +90,22 @@ static uint32_t os_kernel_is_active (void) {
8290
}
8391

8492
/* Provide libspace for current thread */
93+
void *__user_perthread_libspace (void);
8594
void *__user_perthread_libspace (void) {
86-
osThreadId_t id;
95+
TaskHandle_t id;
8796
uint32_t n;
8897

8998
if (!os_kernel_is_active()) {
9099
return (void *)&os_libspace[OS_THREAD_LIBSPACE_NUM][0];
91100
}
92101

93-
id = osThreadGetId();
102+
id = xTaskGetCurrentTaskHandle();
103+
94104
for (n = 0U; n < OS_THREAD_LIBSPACE_NUM; n++) {
95105
if (os_libspace_id[n] == NULL) {
106+
96107
os_libspace_id[n] = id;
108+
97109
return (void *)&os_libspace[n][0];
98110
}
99111
if (os_libspace_id[n] == id) {
@@ -106,6 +118,11 @@ void *__user_perthread_libspace (void) {
106118

107119
/*----------------------------------------------------------------------------*/
108120

121+
#if (OS_MUTEX_CLIB_NUM > 0)
122+
static StaticSemaphore_t clib_mutex_cb[OS_MUTEX_CLIB_NUM];
123+
static SemaphoreHandle_t clib_mutex_id[OS_MUTEX_CLIB_NUM];
124+
#endif
125+
109126
/* Define mutex object and function prototypes */
110127
typedef void *mutex;
111128

@@ -117,7 +134,30 @@ __USED void _mutex_free (mutex *m);
117134

118135
/* Initialize mutex */
119136
int _mutex_initialize(mutex *m) {
120-
*m = osMutexNew(NULL);
137+
#if (OS_MUTEX_CLIB_NUM > 0)
138+
uint32_t i;
139+
#endif
140+
141+
*m = NULL;
142+
143+
#if (OS_MUTEX_CLIB_NUM > 0)
144+
for (i = 0U; i < OS_MUTEX_CLIB_NUM; i++) {
145+
if (clib_mutex_id[i] == NULL) {
146+
/* Create mutex using static memory */
147+
clib_mutex_id[i] = xSemaphoreCreateMutexStatic(&clib_mutex_cb[i]);
148+
149+
/* Return mutex id */
150+
*m = clib_mutex_id[i];
151+
152+
return 1;
153+
}
154+
}
155+
#endif
156+
if (os_kernel_is_active()) {
157+
/* Create mutex using dynamic memory */
158+
*m = xSemaphoreCreateMutex();
159+
}
160+
121161
if (*m == NULL) {
122162
return 0;
123163
}
@@ -126,21 +166,37 @@ int _mutex_initialize(mutex *m) {
126166

127167
/* Acquire mutex */
128168
void _mutex_acquire(mutex *m) {
169+
129170
if (os_kernel_is_active()) {
130-
osMutexAcquire(*m, osWaitForever);
171+
xSemaphoreTake(*m, portMAX_DELAY);
131172
}
132173
}
133174

134175
/* Release mutex */
135176
void _mutex_release(mutex *m) {
177+
136178
if (os_kernel_is_active()) {
137-
osMutexRelease(*m);
179+
xSemaphoreGive(*m);
138180
}
139181
}
140182

141-
/* // Free mutex */
183+
/* Free mutex */
142184
void _mutex_free(mutex *m) {
143-
osMutexDelete(*m);
185+
#if (OS_MUTEX_CLIB_NUM > 0)
186+
uint32_t i;
187+
#endif
188+
189+
vSemaphoreDelete(*m);
190+
191+
#if (OS_MUTEX_CLIB_NUM > 0)
192+
/* Check if mutex was using static memory */
193+
for (i = 0U; i < OS_MUTEX_CLIB_NUM; i++) {
194+
if (*m == clib_mutex_id[i]) {
195+
clib_mutex_id[i] = NULL;
196+
break;
197+
}
198+
}
199+
#endif
144200
}
145201

146202
#endif

CMSIS/RTOS2/FreeRTOS/Source/cmsis_os2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ typedef struct {
9595
} TimerCallback_t;
9696

9797
/* Kernel initialization state */
98-
static osKernelState_t KernelState;
98+
static osKernelState_t KernelState = osKernelInactive;
9999

100100
/*
101101
Heap region definition used by heap_5 variant
@@ -169,7 +169,7 @@ osStatus_t osKernelInitialize (void) {
169169
}
170170
else {
171171
if (KernelState == osKernelInactive) {
172-
EvrFreeRTOSSetup();
172+
EvrFreeRTOSSetup(0U);
173173
#if defined(RTE_RTOS_FreeRTOS_HEAP_5) && (HEAP_5_REGION_SETUP == 1)
174174
vPortDefineHeapRegions (configHEAP_5_REGIONS);
175175
#endif

CMSIS/RTOS2/FreeRTOS/Source/freertos_evr.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,33 @@
199199
#endif /* RTE_Compiler_EventRecorder */
200200

201201
/* Event Recorder initialization and level filter setup */
202-
void EvrFreeRTOSSetup (void) {
202+
void EvrFreeRTOSSetup (uint32_t reset) {
203203
#if !defined(EVR_FREERTOS_DISABLE)
204-
#if (configEVR_INITIALIZE != 0)
205-
EventRecorderInitialize(EVR_INIT_RECORDING, EVR_INIT_START);
206-
#endif
207-
208-
#if (configEVR_SETUP_LEVEL != 0)
209-
EventRecorderEnable(configEVR_LEVEL_TASKS, EvtFreeRTOSTasksNo, EvtFreeRTOSTasksNo);
210-
EventRecorderEnable(configEVR_LEVEL_QUEUE, EvtFreeRTOSQueueNo, EvtFreeRTOSQueueNo);
211-
EventRecorderEnable(configEVR_LEVEL_TIMERS, EvtFreeRTOSTimersNo, EvtFreeRTOSTimersNo);
212-
EventRecorderEnable(configEVR_LEVEL_EVENTGROUPS, EvtFreeRTOSEventGroupsNo, EvtFreeRTOSEventGroupsNo);
213-
EventRecorderEnable(configEVR_LEVEL_HEAP, EvtFreeRTOSHeapNo, EvtFreeRTOSHeapNo);
214-
EventRecorderEnable(configEVR_LEVEL_STREAMBUFFER, EvtFreeRTOSStreamBufNo, EvtFreeRTOSStreamBufNo);
215-
#endif
216-
217-
EventRecord2(EvtFreeRTOSTasks_TaskTrackingReset, 0U, 0U);
204+
static uint8_t init = 0U;
205+
206+
if (reset != 0U) {
207+
init = 0U;
208+
}
209+
210+
if (init == 0U) {
211+
init = 1U;
212+
#if (configEVR_INITIALIZE != 0)
213+
EventRecorderInitialize(EVR_INIT_RECORDING, EVR_INIT_START);
214+
#endif
215+
216+
#if (configEVR_SETUP_LEVEL != 0)
217+
EventRecorderEnable(configEVR_LEVEL_TASKS, EvtFreeRTOSTasksNo, EvtFreeRTOSTasksNo);
218+
EventRecorderEnable(configEVR_LEVEL_QUEUE, EvtFreeRTOSQueueNo, EvtFreeRTOSQueueNo);
219+
EventRecorderEnable(configEVR_LEVEL_TIMERS, EvtFreeRTOSTimersNo, EvtFreeRTOSTimersNo);
220+
EventRecorderEnable(configEVR_LEVEL_EVENTGROUPS, EvtFreeRTOSEventGroupsNo, EvtFreeRTOSEventGroupsNo);
221+
EventRecorderEnable(configEVR_LEVEL_HEAP, EvtFreeRTOSHeapNo, EvtFreeRTOSHeapNo);
222+
EventRecorderEnable(configEVR_LEVEL_STREAMBUFFER, EvtFreeRTOSStreamBufNo, EvtFreeRTOSStreamBufNo);
223+
#endif
224+
225+
EventRecord2(EvtFreeRTOSTasks_TaskTrackingReset, 0U, 0U);
226+
}
227+
#else
228+
(void)reset;
218229
#endif
219230
}
220231

DoxyGen/General/src/cmsis_freertos.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ File/Directory |Content
5656
\page cm_revisionHistory Revision History
5757

5858
<table class="cmtable" summary="Revision History">
59+
<tr>
60+
<td>10.0.2-dev4</td>
61+
<td>
62+
<p><b>FreeRTOS V10.1.1</b></p>
63+
<p>Maintenance release for CMSIS 5.4.0:
64+
<ul>
65+
<li>Updated ARM standard C library interface</li>
66+
<li>Added reset option for \ref EvrFreeRTOSSetup</li>
67+
</ul>
68+
</td>
69+
</tr>
70+
<tr>
71+
<td>10.0.2-dev3</td>
72+
<td>
73+
<p><b>FreeRTOS V10.1.1</b></p>
74+
<p>Maintenance release for CMSIS 5.4.0:
75+
<ul>
76+
<li>Added Event Recorder configuration</li>
77+
<li>Corrected CMSIS-FreeRTOS component viewer linked list processing</li>
78+
</ul>
79+
</td>
80+
</tr>
5981
<tr>
6082
<td>10.0.2-dev2</td>
6183
<td>

DoxyGen/General/src/freertos_evr.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ The steps are described under \ref cre_freertos_proj.
1414
*/
1515

1616
/**
17-
\fn void EvrFreeRTOSSetup (void)
17+
\fn void EvrFreeRTOSSetup (uint32_t reset)
1818
\details
1919
The function \b EvrFreeRTOSSetup initializes Event Recorder and configures recording level filter. It must be called before any event is sent to the Event Recorder.
2020

21+
The argument \a reset specifies if reset of previously applied configuration is performed in case if EvrFreeRTOSSetup was already called.
22+
2123
Behavior of this function execution is defined with Event Recorder Configuration (\ref cmsis_freertos_evr_config). Calling this function has
2224
no effect when Event Recorder component is not selected.
2325

0 commit comments

Comments
 (0)