Skip to content

Commit

Permalink
Merge pull request #6821 from deepikabhavnani/system_stats
Browse files Browse the repository at this point in the history
System stats - API addition
  • Loading branch information
Cruz Monrreal committed May 21, 2018
2 parents b165e9c + 1961428 commit 97b1615
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
68 changes: 68 additions & 0 deletions TESTS/mbed_platform/stats_sys/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest/utest.h"

#include "mbed.h"

#if !defined(MBED_SYS_STATS_ENABLED)
#error [NOT_SUPPORTED] test not supported
#endif

using namespace utest::v1;

void test_sys_info()
{
mbed_stats_sys_t stats;
mbed_stats_sys_get(&stats);

#if defined(MBED_VERSION)
TEST_ASSERT_NOT_EQUAL(0, stats.os_version);
#endif

#if defined(__CORTEX_M)
TEST_ASSERT_NOT_EQUAL(0, stats.cpu_id);
#endif

#if defined(__IAR_SYSTEMS_ICC__)
TEST_ASSERT_EQUAL(IAR, stats.compiler_id);
#elif defined(__CC_ARM)
TEST_ASSERT_EQUAL(ARM, stats.compiler_id);
#elif defined(__GNUC__)
TEST_ASSERT_EQUAL(GCC_ARM, stats.compiler_id);
#endif
TEST_ASSERT_NOT_EQUAL(0, stats.compiler_version);
}

Case cases[] = {
Case("Test Sys Info", test_sys_info)
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto");
return greentea_test_setup_handler(number_of_cases);
}

Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);

int main()
{
Harness::run(specification);
}
31 changes: 29 additions & 2 deletions platform/mbed_stats.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "mbed_assert.h"
#include "mbed_stats.h"
#include <string.h>
#include <stdlib.h>
#include "mbed_assert.h"

#include "device.h"
#ifdef MBED_CONF_RTOS_PRESENT
#include "cmsis_os2.h"
#elif defined(MBED_STACK_STATS_ENABLED) || defined(MBED_THREAD_STATS_ENABLED)
Expand Down Expand Up @@ -96,6 +97,32 @@ size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count)
osKernelUnlock();
free(threads);
#endif

return i;
}

void mbed_stats_sys_get(mbed_stats_sys_t *stats)
{
MBED_ASSERT(stats != NULL);
memset(stats, 0, sizeof(mbed_stats_sys_t));

#if defined(MBED_SYS_STATS_ENABLED)
#if defined(MBED_VERSION)
stats->os_version = MBED_VERSION;
#endif
#if defined(__CORTEX_M)
stats->cpu_id = SCB->CPUID;
#endif
#if defined(__IAR_SYSTEMS_ICC__)
stats->compiler_id = IAR;
stats->compiler_version = __VER__;
#elif defined(__CC_ARM)
stats->compiler_id = ARM;
stats->compiler_version = __ARMCC_VERSION;
#elif defined(__GNUC__)
stats->compiler_id = GCC_ARM;
stats->compiler_version = (__GNUC__ * 10000 + __GNUC_MINOR__ * 100);
#endif

#endif
return;
}
28 changes: 27 additions & 1 deletion platform/mbed_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern "C" {
#endif

#ifdef MBED_ALL_STATS_ENABLED
#define MBED_SYS_STATS_ENABLED 1
#define MBED_STACK_STATS_ENABLED 1
#define MBED_HEAP_STATS_ENABLED 1
#define MBED_THREAD_STATS_ENABLED 1
Expand Down Expand Up @@ -85,7 +86,6 @@ size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
/**
* struct mbed_stats_thread_t definition
*/

typedef struct {
uint32_t id; /**< Thread Object Identifier */
uint32_t state; /**< Thread Object State */
Expand All @@ -105,6 +105,32 @@ typedef struct {
*/
size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count);

/**
* enum mbed_compiler_id_t definition
*/
typedef enum {
ARM = 1, /**< ARM */
GCC_ARM, /**< GNU ARM */
IAR /**< IAR */
} mbed_compiler_id_t;

/**
* struct mbed_stats_sys_t definition
*/
typedef struct {
uint32_t os_version; /**< Mbed OS Version (Release only) */
uint32_t cpu_id; /**< CPUID Register data (Cortex-M only supported) */
mbed_compiler_id_t compiler_id; /**< Compiler ID \ref mbed_compiler_id_t */
uint32_t compiler_version; /**< Compiler version */
} mbed_stats_sys_t;

/**
* Fill the passed in sys stat structure with system stats.
*
* @param stats A pointer to the mbed_stats_sys_t structure to fill
*/
void mbed_stats_sys_get(mbed_stats_sys_t *stats);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 97b1615

Please sign in to comment.