Skip to content

Commit 97b1615

Browse files
author
Cruz Monrreal
authored
Merge pull request #6821 from deepikabhavnani/system_stats
System stats - API addition
2 parents b165e9c + 1961428 commit 97b1615

File tree

3 files changed

+124
-3
lines changed

3 files changed

+124
-3
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
/* mbed Microcontroller Library
3+
* Copyright (c) 2018 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "greentea-client/test_env.h"
19+
#include "unity/unity.h"
20+
#include "utest/utest.h"
21+
22+
#include "mbed.h"
23+
24+
#if !defined(MBED_SYS_STATS_ENABLED)
25+
#error [NOT_SUPPORTED] test not supported
26+
#endif
27+
28+
using namespace utest::v1;
29+
30+
void test_sys_info()
31+
{
32+
mbed_stats_sys_t stats;
33+
mbed_stats_sys_get(&stats);
34+
35+
#if defined(MBED_VERSION)
36+
TEST_ASSERT_NOT_EQUAL(0, stats.os_version);
37+
#endif
38+
39+
#if defined(__CORTEX_M)
40+
TEST_ASSERT_NOT_EQUAL(0, stats.cpu_id);
41+
#endif
42+
43+
#if defined(__IAR_SYSTEMS_ICC__)
44+
TEST_ASSERT_EQUAL(IAR, stats.compiler_id);
45+
#elif defined(__CC_ARM)
46+
TEST_ASSERT_EQUAL(ARM, stats.compiler_id);
47+
#elif defined(__GNUC__)
48+
TEST_ASSERT_EQUAL(GCC_ARM, stats.compiler_id);
49+
#endif
50+
TEST_ASSERT_NOT_EQUAL(0, stats.compiler_version);
51+
}
52+
53+
Case cases[] = {
54+
Case("Test Sys Info", test_sys_info)
55+
};
56+
57+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
58+
{
59+
GREENTEA_SETUP(20, "default_auto");
60+
return greentea_test_setup_handler(number_of_cases);
61+
}
62+
63+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
64+
65+
int main()
66+
{
67+
Harness::run(specification);
68+
}

platform/mbed_stats.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
#include "mbed_assert.h"
12
#include "mbed_stats.h"
23
#include <string.h>
34
#include <stdlib.h>
4-
#include "mbed_assert.h"
55

6+
#include "device.h"
67
#ifdef MBED_CONF_RTOS_PRESENT
78
#include "cmsis_os2.h"
89
#elif defined(MBED_STACK_STATS_ENABLED) || defined(MBED_THREAD_STATS_ENABLED)
@@ -96,6 +97,32 @@ size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count)
9697
osKernelUnlock();
9798
free(threads);
9899
#endif
99-
100100
return i;
101101
}
102+
103+
void mbed_stats_sys_get(mbed_stats_sys_t *stats)
104+
{
105+
MBED_ASSERT(stats != NULL);
106+
memset(stats, 0, sizeof(mbed_stats_sys_t));
107+
108+
#if defined(MBED_SYS_STATS_ENABLED)
109+
#if defined(MBED_VERSION)
110+
stats->os_version = MBED_VERSION;
111+
#endif
112+
#if defined(__CORTEX_M)
113+
stats->cpu_id = SCB->CPUID;
114+
#endif
115+
#if defined(__IAR_SYSTEMS_ICC__)
116+
stats->compiler_id = IAR;
117+
stats->compiler_version = __VER__;
118+
#elif defined(__CC_ARM)
119+
stats->compiler_id = ARM;
120+
stats->compiler_version = __ARMCC_VERSION;
121+
#elif defined(__GNUC__)
122+
stats->compiler_id = GCC_ARM;
123+
stats->compiler_version = (__GNUC__ * 10000 + __GNUC_MINOR__ * 100);
124+
#endif
125+
126+
#endif
127+
return;
128+
}

platform/mbed_stats.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#endif
3131

3232
#ifdef MBED_ALL_STATS_ENABLED
33+
#define MBED_SYS_STATS_ENABLED 1
3334
#define MBED_STACK_STATS_ENABLED 1
3435
#define MBED_HEAP_STATS_ENABLED 1
3536
#define MBED_THREAD_STATS_ENABLED 1
@@ -85,7 +86,6 @@ size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
8586
/**
8687
* struct mbed_stats_thread_t definition
8788
*/
88-
8989
typedef struct {
9090
uint32_t id; /**< Thread Object Identifier */
9191
uint32_t state; /**< Thread Object State */
@@ -105,6 +105,32 @@ typedef struct {
105105
*/
106106
size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count);
107107

108+
/**
109+
* enum mbed_compiler_id_t definition
110+
*/
111+
typedef enum {
112+
ARM = 1, /**< ARM */
113+
GCC_ARM, /**< GNU ARM */
114+
IAR /**< IAR */
115+
} mbed_compiler_id_t;
116+
117+
/**
118+
* struct mbed_stats_sys_t definition
119+
*/
120+
typedef struct {
121+
uint32_t os_version; /**< Mbed OS Version (Release only) */
122+
uint32_t cpu_id; /**< CPUID Register data (Cortex-M only supported) */
123+
mbed_compiler_id_t compiler_id; /**< Compiler ID \ref mbed_compiler_id_t */
124+
uint32_t compiler_version; /**< Compiler version */
125+
} mbed_stats_sys_t;
126+
127+
/**
128+
* Fill the passed in sys stat structure with system stats.
129+
*
130+
* @param stats A pointer to the mbed_stats_sys_t structure to fill
131+
*/
132+
void mbed_stats_sys_get(mbed_stats_sys_t *stats);
133+
108134
#ifdef __cplusplus
109135
}
110136
#endif

0 commit comments

Comments
 (0)